PHP array_diff() functionThe 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 Functions
|