3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php # similar to $source array, but implemented using a function function getSource() { return [ 'subarray' => ['item' => 'old value ---'] ]; } # $ref3 is assigned to result of getSource() right in the foreach() foreach ( $ref3 = getSource() as &$subarray ) { $subarray['item'] = 'NEW value'; echo $subarray['item'], PHP_EOL; echo $ref3['subarray']['item'], PHP_EOL; } echo PHP_EOL;
based on VmA80
Output for 7.0.0 - 7.2.0
NEW value old value ---
Output for 5.5.24 - 5.6.28
NEW value NEW value
Output for 5.4.11 - 5.4.45
Parse error: syntax error, unexpected '&' in /in/NR0Fo on line 10
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/NR0Fo on line 5
Process exited with code 255.