3v4l.org

run code in 200+ 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 - 7.1.10
Array ( [and] => Array ( [like] => red [and] => Array ( [like] => white [and] => Array ( [like] => blue ) ) ) )