note 111706 deleted from function.array-diff by aharvey
| From: | aharvey@php.net | Date: | Wed, 20 Mar 2013 18:49:29 +0000 |
| Subject: | note 111706 deleted from function.array-diff by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194139@lists.php.net to get a copy of this message | ||
Note Submitter: wesleymahler at me dot com
----
This is a function I built to go through a multi-dimensional array and return the difference in an
array.
/*
* This function will go through every level of an array
* to find all of the differences.
*/
function multidimensional_array_diff($arr1, $arr2) {
//first take the differnces between the base array
$diff = array_diff($arr1, $arr2);
//now itterate through all of the sub-arrays, if any exist
foreach($arr1 as $key => $value) {
//if it found a sub-array, perform the same function
if (is_array($arr1[$key]))
$diff[$key] = my_array_diff($arr1[$key], $arr2[$key]);
//if it returns an empty array, which sometimes it does, clear it out
if (empty($diff[$key]))
unset($diff[$key]);
}
//return the difference of the array
return $diff;
}