Php array udiff uassoc
From w3cyberlearnings
Contents |
PHP function array_udiff_uassoc
This function computes the difference of arrays with additional index check, compares data and indexes by a callback function
Syntax array_udiff_uassoc
- array1: The first array.
- array2: The second array.
- array3(optional): The third array.
- callback1:The callback comparison function. The user supplied callback function is used for comparison. It must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
The comparison of arrays' data is performed by using an user-supplied callback : data_compare_func. In this aspect the behaviour is opposite to the behaviour of array_diff_assoc which uses internal function for comparison. callback
- callback2: The comparison of keys (indices) is done also by the callback function key_compare_func. This behaviour is unlike what array_udiff_assoc does, since the latter compares the indices by using an internal function.
array_udiff_uassoc(array, array2,...,callback1, callback2);
Example 1
<?php $person1 = array('bob' => 32, 'mark' => 12, 'janny' => 8); $person2 = array('bob' => 23, 'Mark' => 21, 'joke' => 31); function firstf($k1, $k2) { if ($k1 == $k2) { return 0; } else { return -1; } } function secondf($k1, $k2) { if ($k1 == $k2) { return 0; } else { return -1; } } $records = array_udiff_uassoc($person1, $person2,"firstf","secondf"); print_r($records); ?>
Output
Array ( [bob] => 32 [mark] => 12 [janny] => 8 )
Related Links
- array_change_key_case
- array_chunk
- array_combine
- array_count_values
- array_diff_assoc
- array_diff_key
- array_diff_uassoc
- array_diff_ukey
- array_diff
- array_fill_keys
- array_fill
- array_filter
- array_flip
- array_intersect_assoc
- array_intersect_key
- array_intersect_uassoc
- array_intersect_ukey
- array_intersect
- array_key_ exists
- array_keys