3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
41.36 ms | 402 KiB | 5 Q