Articles on Trending Technologies

Technical articles with clear explanations and examples

PHP program to print the number pattern

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

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 More

PHP program to print a pattern of pyramid

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

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 More

How to check for multidimensional nature of an array in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

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 More

Removing empty array elements in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 750 Views

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 More

Merging duplicate values into multi-dimensional array in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 859 Views

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 More

Removing duplicate elements from an array in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 886 Views

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 More

PHP program to find standard deviation of values within an array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 983 Views

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 More

Redirection in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 7K+ Views

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

The internal working of the 'foreach' loop in PHP

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 293 Views

The 'foreach' loop in PHP helps in accessing key value pairs within an array. The 'foreach' loop works with arrays only, with the advantage that a loop counter wouldn't need to be initialized. In addition to this, no condition needs to be set that would be needed to exit out of the loop. The 'foreach' loop implicitly does this too. Basic Foreach Syntax The foreach loop has two syntax variations − foreach ($array as $value) { // Process each value } foreach ($array as $key => $value) { ...

Read More

How to delete an element from an array in PHP and re-index the array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In PHP, you can delete an element from an array using the unset() function. However, this creates gaps in the array indices. To re−index the array with consecutive numeric keys, use the array_values() function. Using unset() and array_values() The unset() function removes an element by its key, while array_values() returns a new array with consecutive numeric indices ? Original array: array(5) { [0]=> string(4) "this" [1]=> string(2) "is" [2]=> string(1) "a" [3]=> string(6) "sample" ...

Read More
Showing 22371–22380 of 61,297 articles
Advertisements