Php array udiff assoc
From w3cyberlearnings
Contents |
PHP function array_udiff_assoc
This function computes the difference of arrays with additional index check, compares data by a callback function
Syntax array_udiff_assoc
- array1 : array input 1
- array2 : array input 2
- array3 : array input 3
- callback : user-defined function
array_udiff_assoc(array1, array2, array3, callback);
Note
The two functions are almost the same. The array_udiff_assoc function compares the DATA with the user supplied function, and [[php array_diff_uassoc|array_diff_uassoc()]function compares the INDEX with the user supplied function.
Example 1
<?php // call back function to compare two score function check_score($vscore1, $vscore2) { if ($vscore1 == $vscore2) { return 0; } else if ($vscore1 > $vscore2) { return 1; } else { return -1; } } $check_score = array_udiff_assoc( array(4 => 'mark', 3 => 'john', 2 => 'jake'), array(4 => 'mark', 3 => 'john', 12 => 'jake'), "check_score"); print_r($check_score); ?>
Output
Array ( [2] => jake )
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