note 39111 deleted from control-structures.foreach by tomsommer

From: Date: Wed, 18 Aug 2004 19:32:00 +0000
Subject: note 39111 deleted from control-structures.foreach by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74915@lists.php.net to get a copy of this message
Note Submitter: markus_mcn at hotmail dot com ---- 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

« previous php.notes (#74915) next »