note 53656 added to function.array-combine
| From: | imilanez at gmail dot com | Date: | Wed, 08 Jun 2005 14:01:34 +0000 |
| Subject: | note 53656 added to function.array-combine | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-90117@lists.php.net to get a copy of this message | ||
Seeing as how array_combine is a PHP5 only function I came up with the following to use on PHP4.
Since the restrictions for using array_combine is that both the keys array and the values array have
equal amount of rows you can do this in PHP4
<?php
$keys = array('yellow', 'green', 'red');
$values = array('banana', 'pear', 'cherry');
$combinedArray = array();
if(count($keys) == count($values)){
for($x=0; $x<count($keys); $x++)
$combinedArray[$keys[$x]] = $values[$x];
}
}
?>
This returns:
combinedArray['yellow'] = banana
combinedArray['green'] = pear
combinedArray['red'] = cherry
----
Manual Page -- http://www.php.net/manual/en/function.array-combine.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+53656
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53656&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53656&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53656&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53656&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53656&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+53656&report=yes
Search -- http://master.php.net/manage/user-notes.php