I want to create an array that contains multiple arrays. Each with a name. My code is pretty basic:
$main_array = array();
$sub_array = array();
$example1 = array("value1");
$example2 = array("value2");
$example3 = array("value3");
array_push($sub_array,$example1);
array_push($sub_array,$example2);
array_push($sub_array,$example3);
array_push($main_array,$sub_array);
This produces the following result:
Array
(
[0] => Array
(
[0] => Array
(
[0] => value1
)
[1] => Array
(
[0] => value2
)
[2] => Array
(
[0] => value3
)
)
)
I was hoping I could have something like this instead:
["main_array"] => Array
(
["sub_array"] => Array
(
["example1"] => Array
(
[0] => value1
)
["example2"] => Array
(
[0] => value2
)
["example3"] => Array
(
[0] => value3
)
)
)
Is that even possible?
try with this
$sub_array['example1'] = $example1;
$sub_array['example2'] = $example2;
$sub_array['example3'] = $example3;
instead of
array_push($sub_array,$example1);
array_push($sub_array,$example2);
array_push($sub_array,$example3);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With