note 119271 deleted from function.array-diff by cmb

From: Date: Sat, 30 Apr 2016 11:51:14 +0000
Subject: note 119271 deleted from function.array-diff by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-205408@lists.php.net to get a copy of this message
Note Submitter: emeka at echeruo at gmail dot com ---- 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; }

« previous php.notes (#205408) next »