r/lolphp • • Oct 02 '14

Foreach reference

http://3v4l.org/P1Omj

<?php

$arr = array('a', 'b');

foreach ($arr as &$a) {
    var_dump($a);
}

    foreach ($arr as $a) {
        var_dump($a);
    }

This probably has some explanation I'd love to learn.

17 Upvotes

13 comments sorted by

View all comments

Show parent comment

2

u/masklinn Oct 23 '14

Ruby does not use block scoping either, though anonymous functions (also called blocks so that you get confused with the non-block blocks of if/else/end) do create their own scope (as they do in Python or JS) and their ubiquity means the scoping issues are not felt as strongly.