3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fruit = array(); $fruit[] = array('id' => 1, 'name' => 'Banana 1'); $fruit[] = array('id' => 1, 'name' => 'Pear 1'); $fruit[] = array('id' => 1, 'name' => 'Mango 1'); $fruit[] = array('id' => 2, 'name' => 'Banana 2'); $fruit[] = array('id' => 2, 'name' => 'Pear 2'); $fruit[] = array('id' => 2, 'name' => 'Mango 2'); $render = array(); $render = array_merge($render, array('fruit' => $fruit)); $render = array_merge_recursive($render, array('pieces' => get_pieces(1))); $render = array_merge($render, array('fruit' => $fruit)); $render = array_merge_recursive($render, array('pieces' => get_pieces(2))); function get_pieces($id) { $pieces = array(); switch ($id) { case 1: $pieces[] = array('number' => 1); $pieces[] = array('number' => 2); break; case 2: $pieces[] = array('number' => 3); $pieces[] = array('number' => 4, 'qwerty' => 1); break; } return $pieces; } var_dump($render);

preferences:
24.8 ms | 406 KiB | 5 Q