Beldion Bryan Balanan Beldion Bryan Balanan - 1 year ago 74
PHP Question

doing an array_push to an array inside an array

$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);

Is there a way where I can insert
inside of
after putting
inside of
? The outcome I want is possible by moving
array_push($mainstack, $menustack);
to the last line, but I am really looking for a way where I can just insert an array to an existing stack of arrays.

Answer Source

You just need to know the index of $menustack inside of $mainstack

$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);

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download