PHP array_diff() Function6 Jan 2025 | 2 min read The array_diff() function compares two or more arrays and returns an array with the keys and values from the first array, only if the value is not present in any of the other arrays. This function was introduced in PHP 4.0. Syntax
Return TypeIt returns an array containing the entries from array1 that are not present in any of the other arrays. Important note- Only the value is used in comparisonExample 1Output: Array ( [0] => netbeans ) Example 2Output: Array ( [4] => zend ) Example 3Output: Array ( [2] => c [3] => d [4] => e ) Example 4Output: Array ( [3] => yellow ) Difference between array_diff( ) , array_diff_key( ) and array_diff_assoc( )Output: Array( [fruit1] => apple ) Array ( [friut3] => mango ) Array ( [fruit1] => apple [friut3] => mango ) On using array_diff, the value that exists in $array1, and not exists in another array, is returned as the resultant array. Similarly, the other PHP array difference functions return the different element of the array. Next TopicPhp-array-diff-key-function |
The array_values( ) function is an inbuilt function of PHP. It is used to get an array of values from another array that may contain key-value pairs. This function was introduced in PHP 4.0. Syntax array array_values ( array $array ); Parameters Parameter Description Is compulsory array Specifying an array. compulsory Return Values The array_values( )...
1 min read
PHP array_fill( ) Function The array_fill( ) function is used to fill an array with values. This function creates a user-defined array with a given pre-filled value. It was introduced in PHP 4. Syntax array array_fill ( int $start_index , int $num , mixed $value ) Parameter Parameter Description Is compulsory starting_index The first...
1 min read
The array_intersect_assoc() is used to create an array containing keys and values of the first array whose values (i.e., from the first array) are present in all other arrays, while the index of values is same for all the given arrays. This function was introduced...
1 min read
The array_replace_recursive() function is an inbuilt function of PHP. The array_replace_recursive( ) function is used to replace the values from passed arrays into the first array recursively. This function was introduced in PHP 5.3.0. Syntax array array_replace_recursive ( array $array1 [, array $... ] ); Parameter Parameter Description Is compulsory array1 Specifies an...
2 min read
PHP sizeof() Function The sizeof( ) function is an alias of count( ) function. The sizeof( ) function returns the number of elements in an array. This function was introduced in PHP 4.0. Syntax intsizeof(array, mode); Parameter Parameter Description Is compulsory array Specifies the array to use. compulsory mode Specifies the mode. Possible values: 0 - Default. Does...
1 min read
PHP usort( ) Function The PHP usort( ) function is used to sort an array by its value using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. This function was...
2 min read
The count( ) function is an inbuilt function of PHP, and it is used to count the elements of an array or the properties of an object. This function was introduced in PHP 4.0. Syntax int count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] ); Parameters Parameter Description Is...
1 min read
PHP asort() Function The asort( ) function is an inbuilt function of PHP. The asort( ) function is used to sort an associative array in ascending order, according to the value. This function was introduced in PHP 4.0. Syntax bool asort ( array &$array [, int $sort_flags =...
1 min read
The array_sum( ) function is an inbuilt function of PHP. The array_sum( ) function calculates the sum of values in an array and returns the sum of values in an array as an integer or float. This function was introduced in PHP 4.0.4. Syntax number array_sum (...
1 min read
The array_product() function is inbuilt function of PHP. The array_product() function calculates the product of an array. This function was introduced in PHP 5.1.0. Syntax number array_product ( array $array ); Parameters Parameter Description Required/Optional array Specifies an array. compulsory Return Type The array_product() function returns the product as an integer or float. Example 1 <?php $prime=array(2,3,5,7); print_r(array_product($prime)); ?> Output: 210 Example 2 <?php $even=array(2,6); print_r($even); print_r(array_product($even)); echo "\n"; $odd=array(7,9); print_r($odd); print_r(array_product($odd)); ?> Output: Array ( ...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India