note 33879 deleted from function.array-combine by sniper
| From: | sniper@php.net | Date: | Mon, 06 Oct 2003 22:57:07 +0000 |
| Subject: | note 33879 deleted from function.array-combine by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57930@lists.php.net to get a copy of this message | ||
Note Submitter: k@skreel.org
----
array_combine for PHP 4.0.6+
function array_combine($keys, $vals)
{ $retour= FALSE;
$limite= count($keys);
if (0!=$limite && $limite==count($vals))
{ $retour= array();
foreach (array_map(NULL, $keys, $vals) as $item)
{ $retour[ $item[0] ]= $item[1]; }
}
return ($retour);
}
it relies on the order of elements e.g.
$a = array(1 => 'green','key' => 'red','yellow');
$b = array(0 => 'avocado','apple','banana');
$c = array_combine($a, $b);
$c would still be
Array
(
[green] => avocado
[red] => apple
[yellow] => banana
)