I'm trying to generate a multi-layered JSON file using php's array function (for 3 separate arrays). I'm essentially using 3 different arrays in php to generate the one Here is the basic code I am using in php:
$full_array = array();
...
$results_array('step1');
foreach($ga->getResults() as $result):
$add_array = array();
$add_array['total'] = $ga->getResults();
array_push($results_array, $add_array);
endforeach;
array_push($full_array, $results_array);
echo json_encode($full_array)
This results in the following:
[
[
"step1",
{
"total": "...."
}
]
]
However, I'm trying to get that "step1" before the brace, so it should look like the following:
[
"step1",
[
{
"total": "...."
}
]
]
Does anybody know how to get the latter format using PHP? I've searched for this answer everywhere but could not find it anywhwere - apologies if there is a duplicate answer. Any help would be greatly appreciated.
$array[] = $var_to_push
– G-Nugget Feb 12 '13 at 21:28