note 75392 deleted from function.array-intersect-key by mazzanet
| From: | mazzanet@php.net | Date: | Sun, 27 May 2007 09:36:46 +0000 |
| Subject: | note 75392 deleted from function.array-intersect-key by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126946@lists.php.net to get a copy of this message | ||
Note Submitter: Maikel
----
You must be careful when using this function because an bug of php is present. Look this:
<?php
header("Content-type: text/plain");
$array1 = array('azul' => 1, 'rojo' => 2, 'verde' => 3,
'morado' => 4, 1=> 1);
$array2 = array('verde' => 5, 'azul' => 6, 'amarillo' => 7,
'cyan' => 8, '1' => 1);
print_r(array_intersect_key($array1, $array2));
?>
it will show:
Array
(
[azul] => 1
[verde] => 3
[1] => 1
)
This problem is present as much in array_intersect_key as in array_keys and even in foreach:
<?php
$a = array ("0"=> 1);
foreach ($a as $key => $value)
{
var_dump($key); //show int(0)
}
?>