3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(3, 4); var_dump($arr); $ref =& $arr[0] ; // this statement causes the weird behaviour. Without it all is ok var_dump($arr); // as expected var_dump(doSomethingTo($arr)); // as expected var_dump($arr); // WHAT JUST HAPPENED? function doSomethingTo($arr) { // $arr BY VALUE foreach($arr as $k => $v) $arr[$k]=$v+1 ; return $arr ; }

preferences:
24.76 ms | 404 KiB | 5 Q