note 61325 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:06:57 +0000 |
| Subject: | note 61325 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153913@lists.php.net to get a copy of this message | ||
Note Submitter: egingell at sisna dot com
----
That is definitely weird.
Anyway, I found out that if you put something like $ary[] in where either the key and/or the value
goes, you'll append all the keys and/or values to that array. Example:
<?php
$array = array(
'num1' => 'a',
'num2' => 'b',
'num3' => 'c'
);
$k = array();
$v = array();
foreach ($array as $k[] => $v[]);
echo '$k => ' . print_r($k, true);
echo '$v => ' . print_r($v, true);
?>
The above code will do this:
$k => Array (
[0] => num1
[1] => num2
[2] => num3
)
$v => Array (
[0] => a
[1] => b
[2] => c
)