$mainstack = array(
'applet' => "Flow"
);
$menustack = array(
'applet' => "Menu",
'repeat' => "2"
);
$dialstack = array(
);
$dial1 = array(
'applet' => "Dial",
'number' => "165465468",
'whisper' => "Yes",
);
$dial2 = array(
'applet' => "Dial",
'number' => "654984",
'whisper' => "No",
);
$dial3 = array(
'applet' => "Dial",
'number' => "398965165",
'whisper' => "Yes",
);
array_push($mainstack, $menustack);
array_push($dialstack, $dial1);
array_push($dialstack, $dial2);
array_push($dialstack, $dial3);
array_push($menustack, $dialstack);
将$dialstack
放入$menustack
后,我是否可以在menustack
内插入$mainstack
?通过将array_push($mainstack, $menustack);
移动到最后一行,我想要的结果是可能的,但我真的在寻找一种方法,我可以将数组插入到现有的数组堆栈中。
答案 0 :(得分:3)
你只需要知道$ mainstack里面$ menustack的索引
$arrayOne = [];
$arrayTwo = [];
$arrayThree = [];
// $arrayOne goes inside of $arrayTwo
array_push($arrayTwo, $arrayOne);
// $arrayThree goes inside of $arrayTwo[0] which is $arrayOne
array_push($arrayTwo[0], $arrayThree);
var_dump($arrayTwo);
答案 1 :(得分:1)
array_push($mainstack,array_merge($menustack,$dialstack));
print_r($mainstack);
首先使用array_merge合并两个数组,然后将其推送到$mainstack