note 119271 added to function.array-diff
| From: | emeka at echeruo at gmail dot com | Date: | Sat, 30 Apr 2016 00:34:55 +0000 |
| Subject: | note 119271 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205403@lists.php.net to get a copy of this message | ||
Computes the difference of all the arrays
/**
* array_diffs â Computes the difference of all the arrays
*
* @param array
*
* array1 - The array to compare from and against
* array2 - The array to compare from and against
* array(n) - More arrays to compare from and against
*
* @return array Returns all the arrays that do contains entries that cannot be matched in any of
the arrays.
*/
function array_diffs() {
$count = func_num_args();
if($count < 2) {
trigger_error('Must provide at least 2 arrays for comparison.');
}
$check = array();
$out = array();
for ($i = 0; $i < $count; $i++) {
if(!is_array(func_get_arg($i))) {
trigger_error('Parameters must be passed as arrays.');
}
foreach(func_get_arg($i) as $key => $value) {
if(is_numeric($key) && !is_numeric($value)) {
if(isset($check[$value]) && $check[$value]['value'] == $value) {
$check[$value]['count'] = $check[$value]['count'] + 1;
} else {
$check[$value]['value'] = $value;
$check[$value]['count'] = 1;
}
} else {
if(isset($check[$key]) && $check[$key]['value'] == $value) {
$check[$key]['count'] = $check[$key]['count'] + 1;
} else {
$check[$key]['value'] = $value;
$check[$key]['count'] = 1;
}
}
}
}
foreach($check as $check_key => $check_value) {
if($check_value['count'] == 1) {
for ($i = 0; $i < $count; $i++) {
foreach(func_get_arg($i) as $key => $value) {
if(is_numeric($key) && !is_numeric($value)) {
if($value == $check_key) {
$out[$i][$key] = $value;
}
} else {
if($key == $check_key) {
$out[$i][$key] = $value;
}
}
}
}
}
}
return $out;
}
----
Server IP: 72.52.91.14
Probable Submitter: 73.83.120.60
----
Manual Page -- http://php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/119271
Del: integrated -- https://master.php.net/note/delete/119271/integrated
Del: useless -- https://master.php.net/note/delete/119271/useless
Del: bad code -- https://master.php.net/note/delete/119271/bad+code
Del: spam -- https://master.php.net/note/delete/119271/spam
Del: non-english -- https://master.php.net/note/delete/119271/non-english
Del: in docs -- https://master.php.net/note/delete/119271/in+docs
Del: other reasons-- https://master.php.net/note/delete/119271
Reject -- https://master.php.net/note/reject/119271
Search -- https://master.php.net/manage/user-notes.php