<?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);
- Output for 5.6.38 - 5.6.40, 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
- array(2) {
["fruit"]=>
array(6) {
[0]=>
array(2) {
["id"]=>
int(1)
["name"]=>
string(8) "Banana 1"
}
[1]=>
array(2) {
["id"]=>
int(1)
["name"]=>
string(6) "Pear 1"
}
[2]=>
array(2) {
["id"]=>
int(1)
["name"]=>
string(7) "Mango 1"
}
[3]=>
array(2) {
["id"]=>
int(2)
["name"]=>
string(8) "Banana 2"
}
[4]=>
array(2) {
["id"]=>
int(2)
["name"]=>
string(6) "Pear 2"
}
[5]=>
array(2) {
["id"]=>
int(2)
["name"]=>
string(7) "Mango 2"
}
}
["pieces"]=>
array(4) {
[0]=>
array(1) {
["number"]=>
int(1)
}
[1]=>
array(1) {
["number"]=>
int(2)
}
[2]=>
array(1) {
["number"]=>
int(3)
}
[3]=>
array(2) {
["number"]=>
int(4)
["qwerty"]=>
int(1)
}
}
}
preferences:
97.49 ms | 410 KiB | 5 Q