FAQ

On 23/10/2013 19:03, Matthew Leverton wrote:
Seems like a natural fit to me.

Does it also work with the new foreach/list combo?

foreach ($array as list(&$a, $b)) {}
Somehow I managed to forget to test that. Apparently, it does:

ajf@raspberrypi ~/PHP/php-src $ sapi/cli/php -r '$arr = [[1,2],[3,4]];
foreach ($arr as list(&$a, $b)) $a = 7; var_dump($arr);'
array(2) {
    [0]=>
    array(2) {
      [0]=>
      int(7)
      [1]=>
      int(2)
    }
    [1]=>
    array(2) {
      [0]=>
      &int(7)
      [1]=>
      int(4)
    }
}

I should probably add a test for this.
--
Andrea Faulds
http://ajf.me/

Search Discussions

Discussion Posts

Previous

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 3 | next ›
Discussion Overview
groupphp-internals @
categoriesphp
postedOct 23, '13 at 5:50p
activeOct 23, '13 at 6:07p
posts3
users2
websitephp.net

2 users in discussion

Andrea Faulds: 2 posts Matthew Leverton: 1 post

People

Translate

site design / logo © 2022 Grokbase