note 61325 added to control-structures.foreach
| From: | egingell at sisna dot com | Date: | Tue, 31 Jan 2006 17:26:48 +0000 |
| Subject: | note 61325 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102774@lists.php.net to get a copy of this message | ||
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
)
----
Server IP: 216.194.113.175
Probable Submitter: 65.100.200.115
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61325
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61325&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61325&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61325&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61325&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61325&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61325&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61325&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61325&report=yes
Search -- http://master.php.net/manage/user-notes.php