note 39111 added to control-structures.foreach
| From: | markus_mcn at hotmail dot com | Date: | Sat, 17 Jan 2004 11:57:38 +0000 |
| Subject: | note 39111 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-63732@lists.php.net to get a copy of this message | ||
Since array_combine only works with PHP 5 it is no good for us PHP 4 users.
Instead you can use this simple code:
<?
// example arrays
$a = array (1, 2, 3, 17);
$b = array ("one", "two", "three", "seventeen");
// merging them into the new array $c
foreach($a as $i => $v)
{
$c[$b[$i]] = $v;
}
// printing result
foreach($c as $k => $v)
{
echo "\$c[$k] => $v.<br>";
}
?>
which prints:
$c[one] => 1.
$c[two] => 2.
$c[three] => 3.
$c[seventeen] => 17.
If you want a more advanced code check out the code by "half_life_fool" (21-Oct-2003
05:28) in the comments for the array_combine function.
// Corny
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39111
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39111&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39111&report=yes
Search -- http://master.php.net/manage/user-notes.php