3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 'a' => 'A', 'b' => 'B', 'c' => 'C'); var_dump($arr); // Taking "$val" as a reference here allows modifying the parent hashtable // directly, i.e. the $val ref "knows" its parent key in some sense foreach ($arr as &$val) { if ($val == 'B') { $val = 'X'; } } unset($arr[2]); var_dump($arr); // However, it doesn't allow you to unset the parent key... foreach ($arr as &$val) { if ($val == 'B') { } } var_dump($arr);

preferences:
68.14 ms | 402 KiB | 5 Q