note 42159 added to function.array-combine
| From: | phpatbenramseydotcom at rn2 dot php dot net | Date: | Wed, 05 May 2004 16:47:54 +0000 |
| Subject: | note 42159 added to function.array-combine | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69256@lists.php.net to get a copy of this message | ||
I'm not sure why there is a need for using array_values() in any of the code below.
Here's what I use in PHP versions < 5.0, and it works quite well. Short, simple, and to the
point.
<?php
function array_combine ($array_keys, $array_values)
{
if (
(count($array_keys) != count($array_values)) ||
(count($array_keys) == 0)
)
{
return false;
}
$array_combined = array();
for ($i = 0; $i < count($array_keys); $i++)
{
$array_combined[$array_keys[$i]] = $array_values[$i];
}
return $array_combined;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.array-combine.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42159
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42159&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42159&report=yes
Search -- http://master.php.net/manage/user-notes.php