note 111706 added to function.array-diff
| From: | wesleymahler at me dot com | Date: | Tue, 19 Mar 2013 20:39:20 +0000 |
| Subject: | note 111706 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194122@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 69.147.83.199
Probable Submitter: 76.21.32.198
----
Manual Page -- http://php.net/manual/en/function.array-diff.php
Edit -- https://master.php.net/note/edit/111706
Del: integrated -- https://master.php.net/note/delete/111706/integrated
Del: useless -- https://master.php.net/note/delete/111706/useless
Del: bad code -- https://master.php.net/note/delete/111706/bad+code
Del: spam -- https://master.php.net/note/delete/111706/spam
Del: non-english -- https://master.php.net/note/delete/111706/non-english
Del: in docs -- https://master.php.net/note/delete/111706/in+docs
Del: other reasons-- https://master.php.net/note/delete/111706
Reject -- https://master.php.net/note/reject/111706
Search -- https://master.php.net/manage/user-notes.php