Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
PHP program to find the total number of date between any two given dates
The date_diff() function can be used to get the difference between two dates. It is a built-in function that returns a DateInterval object containing the difference between the dates. Syntax date_diff(datetime1, datetime2, absolute) Parameters datetime1 − The first date object datetime2 − The second date object absolute (optional) − If set to TRUE, the interval will always be positive Example The following example demonstrates how to find the total number of days between two given dates ? The day difference is: +60 days Using ...
Read MorePHP program to print continuous character pattern triangle
To print continuous character pattern triangle in PHP, we use nested loops to generate a triangular pattern where each row contains consecutive alphabets. The pattern starts with 'A' and continues sequentially across all rows. Example Here's how to create a continuous character pattern triangle ? Output A B C D E F G H I J K L M N O P Q R S T U How It Works The function uses two nested loops to create the triangular pattern. The ...
Read MorePHP program to print the number pattern
To print the number pattern in PHP, we use nested loops where each row contains the row number repeated row number of times. This creates a triangular pattern of numbers. Example Output 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 How It Works The function num_pattern() takes the limit as a parameter. The outer loop runs from 0 to the limit value, and the inner loop prints the current number ...
Read MorePHP program to print a pattern of pyramid
In PHP, you can print a pyramid pattern using nested loops. The pattern involves printing spaces for centering and asterisks to form the pyramid shape. Example Here's how to create a pyramid pattern using a function − Output * * * * * * * * * * * * * * * * * * * * * * * * * * * * How It ...
Read MoreHow to check for multidimensional nature of an array in PHP
In PHP, you can check if an array is multidimensional by examining whether its first element is itself an array. This approach uses sorting to ensure consistent element ordering, then checks the nature of the first element. Using rsort() with isset() and is_array() The following method sorts the array and checks if the first element is an array − Is the array multi-dimensional? bool(true) Alternative Method A simpler approach without sorting − Single array: bool(false) Multi array: bool(true) How It Works ...
Read MoreRemoving empty array elements in PHP
To remove empty array elements in PHP, you can use several approaches. The most common methods include using array_filter() or manually iterating through the array with foreach and unset(). Using foreach and unset() This method manually iterates through the array and removes empty elements ? After removing empty values from the array: This 91 102 is a sample Using array_filter() The array_filter() function provides a cleaner approach to remove empty elements ? Original array elements: 10 Filtered array elements: 6 This 91 ...
Read MoreMerging duplicate values into multi-dimensional array in PHP
In PHP, you can merge duplicate values into a multi-dimensional array by grouping elements based on a common key. This technique helps organize data and eliminate redundant entries by creating sub-arrays for each unique key value. Example Here's how to group array elements by their 'hobby' field − The grouped array elements are: Array ( [Cycling] => Array ( [0] => Array ...
Read MoreRemoving duplicate elements from an array in PHP
In PHP, there are several methods to remove duplicate elements from an array. The most common approaches include using array_unique(), array_flip(), or array_keys() with array_count_values(). Using array_flip() The array_flip() function reverses keys and values. When flipped twice, duplicate values are automatically removed since array keys must be unique − The original array contains Array ( [0] => 45 [1] => 65 [2] => 67 [3] => 99 [4] => 81 [5] => 90 ...
Read MorePHP program to find standard deviation of values within an array
Standard deviation measures how spread out values are from the average in a dataset. In PHP, you can calculate it by finding the mean, computing variances, and taking the square root of the average variance. Syntax The formula for standard deviation is ? Standard Deviation = sqrt(sum((value - mean)²) / count) Example Here's how to create a function to calculate standard deviation ? The standard deviation of elements in the array is 35.423156268181 How It Works The std_deviation() function works in the following steps ...
Read MoreRedirection in PHP
The header function in PHP can be used to redirect the user from one page to another. It is an in-built function that sends raw HTTP header to the destination (client). Syntax header($header_value, $replace_value, $http_response_code) Parameters header_value − The header string to be sent replace_value − Optional boolean that indicates whether to replace a previous similar header (default: true) http_response_code − Optional HTTP response code (default: 302 for redirects) Basic Redirection Example Here's how to redirect to another website − The exit statement is crucial ...
Read More