note 37238 added to function.array-intersect-assoc
| From: | mrmachine at nospam dot mrmachine dot net | Date: | Fri, 07 Nov 2003 10:00:27 +0000 |
| Subject: | note 37238 added to function.array-intersect-assoc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-60063@lists.php.net to get a copy of this message | ||
this is a re-implementation of array_intersect_assoc for php4 versions < 4.3.0. this function
does not use a strict comparison of values for compatibility with the php 4.3.0 version.
function array_intersect_assoc()
{
$args = func_get_args();
$intersection = array();
foreach ($args[0] as $k => $v)
{
$intersection[$k] = $v;
for ($i = 1; $i < count($args); $i++)
{
if (!isset($args[$i][$k]) || $args[$i][$k] != $v)
{
unset($intersection[$k]);
break;
}
}
}
return $intersection;
}
$a1 = array(1, 2, 'x' => 3, '10' => 4);
$a2 = array(2, 2, 'x' => 3, '10' => 4);
$a3 = array(3, 2, 'y' => 3, 10 => '4');
$x = array_intersect_assoc($a1, $a2, $a3);
print_r($x);
----
Manual Page -- http://www.php.net/manual/en/function.array-intersect-assoc.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+37238
Delete -- http://master.php.net/manage/user-notes.php?action=delete+37238&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+37238&report=yes
Search -- http://master.php.net/manage/user-notes.php