note 37238 modified in function.array-intersect-assoc by aidan
| From: | aidan@php.net | Date: | Sat, 26 Jun 2004 07:33:37 +0000 |
| Subject: | note 37238 modified in function.array-intersect-assoc by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71732@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.
<?php
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);
?>
--was--
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);
http://php.net/manual/en/function.array-intersect-assoc.php