Php array udiff
From w3cyberlearnings
Contents |
PHP function array_udiff
This function computes the different of arrays values by using the user-defined function for data comparison.
Syntax array_udiff
- array1: array input 1
- array2: array input 2
- array3: array input 3
- callback: user-defined function for data comparison between arrays
array_udiff(array1, array2, ..., callback);
Example 1
- check for the average score for two plays for each players.
<?php $records = array('Alyssa' => 10, 'Emma' => 3, 'Landon' => 5); $players = array('Alyssa' => 9.21, 'Emma' => 4, 'Landon' => 6); function playercheck($v1, $v2) { $result = ($v1 + $v2) / 2; if ($result >= 9) { return 0; } else { return 1; } } $player_score = array_udiff($records, $players, 'playercheck'); print_r($player_score); ?>
Output
Array ( [Emma] => 3 [Landon] => 5 )
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