note 127659 added to control-structures.foreach
| From: | SanusiHassan at main dot php dot net | Date: | Fri, 23 Sep 2022 16:13:06 +0000 |
| Subject: | note 127659 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219605@lists.php.net to get a copy of this message | ||
destructure array elements
you can unpac nested array elements using the following
<?php
$array = [
[1, 2],
[3, 4],
];
foreach ($array as $v) {
[$a, $b] = $v;
echo "A: $a; B: $b\n";
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 41.44.52.48)
----
Manual Page -- https://php.net/manual/en/control-structures.foreach.php
Edit -- https://main.php.net/note/edit/127659
Del: integrated -- https://main.php.net/note/delete/127659/integrated
Del: useless -- https://main.php.net/note/delete/127659/useless
Del: bad code -- https://main.php.net/note/delete/127659/bad+code
Del: spam -- https://main.php.net/note/delete/127659/spam
Del: non-english -- https://main.php.net/note/delete/127659/non-english
Del: in docs -- https://main.php.net/note/delete/127659/in+docs
Del: other reasons-- https://main.php.net/note/delete/127659
Reject -- https://main.php.net/note/reject/127659
Search -- https://main.php.net/manage/user-notes.php