Re: list() inside a foreach()
| From: | Sherif Ramadan | Date: | Thu, 09 May 2013 16:42:43 +0000 |
| Subject: | Re: list() inside a foreach() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-67377@lists.php.net to get a copy of this message | ||
On Thu, May 9, 2013 at 12:39 PM, Stefan Neufeind <neufeind@php.net> wrote:
> Hi,
>
> trying out the following source I was astonished to see that using
> list() does not work directly in a foreach() but works fine if used
> through a temporary variable.
>
>
Hi,
This feature was already voted in and accepted.
https://wiki.php.net/rfc/foreachlist#vote
It has been implemented in PHP 5.5
> Would allowing using list() inside the foreach()-statement be desired
> behaviour? Or is it just me? :-)
>
>
> $a = array(
> array(5, 'A'),
> array(3, 'B'),
> );
> foreach($a as list($k, $v)) {
> echo $k;
> }
>
> Expected output: 53
>
> Result: syntax error, unexpected 'list' (T_LIST) in ...
>
>
> Works:
> foreach($a as $b) {
> list($k, $v) = $b;
> echo $k;
> }
>
>
> Kind regards,
> Stefan
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>