3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array('red', 'white', 'blue'); $new_array = array(); $temp_array = &$new_array; foreach ($array as $item) { $temp_array = &$temp_array['and']; // $temp_array now equals null, // and it's references to parent array item with key and $temp_array['like'] = $item; } unset($temp_array); print_r($new_array);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [and] => Array ( [like] => red [and] => Array ( [like] => white [and] => Array ( [like] => blue ) ) ) )