我正在尝试使用php的数组函数生成一个多层JSON文件(用于3个独立的数组)。我基本上在php中使用3个不同的数组来生成一个这是我在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)
这导致以下结果:
[
[
"step1",
{
"total": "...."
}
]
]
但是,我试图在大括号之前得到“step1”,所以它应该如下所示:
[
"step1",
[
{
"total": "...."
}
]
]
有人知道如何使用PHP获得后一种格式吗?我到处都搜索过这个答案但却无法找到它 - 如果答案重复,请道歉。任何帮助将不胜感激。
答案 0 :(得分:0)
摆脱$full_array
并执行:
echo json_encode($results_array);