note 110590 added to function.array-intersect
| From: | caffinated | Date: | Sat, 10 Nov 2012 00:13:43 +0000 |
| Subject: | note 110590 added to function.array-intersect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191831@lists.php.net to get a copy of this message | ||
If you're looking for a relatively easy way to strictly intersect keys and values recursively
without array key reordering, here's a simple recursive function:
function array_intersect_recursive($array1, $array2)
{
foreach($array1 as $key => $value)
{
if (!isset($array2[$key]))
{
unset($array1[$key]);
}
else
{
if (is_array($array1[$key]))
{
$array1[$key] = array_intersect_recursive($array1[$key], $array2[$key]);
}
elseif ($array2[$key] !== $value)
{
unset($array1[$key]);
}
}
}
return $array1;
}
----
Server IP: 64.68.200.35
Probable Submitter: 184.69.29.10
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect.php
Edit -- https://master.php.net/note/edit/110590
Del: integrated -- https://master.php.net/note/delete/110590/integrated
Del: useless -- https://master.php.net/note/delete/110590/useless
Del: bad code -- https://master.php.net/note/delete/110590/bad+code
Del: spam -- https://master.php.net/note/delete/110590/spam
Del: non-english -- https://master.php.net/note/delete/110590/non-english
Del: in docs -- https://master.php.net/note/delete/110590/in+docs
Del: other reasons-- https://master.php.net/note/delete/110590
Reject -- https://master.php.net/note/reject/110590
Search -- https://master.php.net/manage/user-notes.php