note 116350 added to control-structures.foreach
| From: | Fred | Date: | Tue, 16 Dec 2014 20:53:34 +0000 |
| Subject: | note 116350 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201208@lists.php.net to get a copy of this message | ||
If you want to use the list for multidimension arrays, you can nest several lists:
<?php
$array = [
[1, 2, array(3, 4)],
[3, 4, array(5, 6)],
];
foreach ($array as list($a, $b, list($c, $d))) {
echo "A: $a; B: $b; C: $c; D: $d;<br>";
};
?>
Will output:
A: 1; B: 2; C: 3; D: 4;
A: 3; B: 4; C: 5; D: 6;
And:
<?php
$array = [
[1, 2, array(3, array(4, 5))],
[3, 4, array(5, array(6, 7))],
];
foreach ($array as list($a, $b, list($c, list($d, $e)))) {
echo "A: $a; B: $b; C: $c; D: $d; E: $e;<br>";
};
Will output:
A: 1; B: 2; C: 3; D: 4; E: 5;
A: 3; B: 4; C: 5; D: 6; E: 7;
?>
----
Server IP: 72.52.91.14
Probable Submitter: 177.40.150.162
----
Manual Page -- http://php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/116350
Del: integrated -- https://master.php.net/note/delete/116350/integrated
Del: useless -- https://master.php.net/note/delete/116350/useless
Del: bad code -- https://master.php.net/note/delete/116350/bad+code
Del: spam -- https://master.php.net/note/delete/116350/spam
Del: non-english -- https://master.php.net/note/delete/116350/non-english
Del: in docs -- https://master.php.net/note/delete/116350/in+docs
Del: other reasons-- https://master.php.net/note/delete/116350
Reject -- https://master.php.net/note/reject/116350
Search -- https://master.php.net/manage/user-notes.php