note 37527 added to function.array-diff
| From: | php-general at lists dot php dot net | Date: | Tue, 18 Nov 2003 21:54:26 +0000 |
| Subject: | note 37527 added to function.array-diff | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60588@lists.php.net to get a copy of this message | ||
From the page:
Note: Please note that this function only checks one dimension of a n-dimensional array. Of course
you can check deeper dimensions by using array_diff($array1[0], $array2[0]);
I've found a way to bypass that. I had 2 arrays made of arrays.
I wanted to extract from the first array all the arrays not found in the second array. So I used the
serialize() function:
function my_serialize(&$arr,$pos){
$arr = serialize($arr);
}
function my_unserialize(&$arr,$pos){
$arr = unserialize($arr);
}
//make a copy
$first_array_s = $first_array;
$second_array_s = $second_array;
// serialize all sub-arrays
array_walk($first_array_s,'my_serialize');
array_walk($second_array_s,'my_serialize');
// array_diff the serialized versions
$diff = array_diff($first_array_s,$second_array_s);
// unserialize the result
array_walk($diff,'my_unserialize');
// you've got it!
print_r($diff);
----
Manual Page -- http://www.php.net/manual/en/function.array-diff.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37527
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37527&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37527&report=yes
Search -- http://master.php.net/manage/user-notes.php