这是我的一段代码:
if($all_pages)
foreach ($all_pages as $page)
{
$all_hokms = $mysqli->query("SELECT * FROM qm_hokm WHERE page_id = ".$page['page_id']."");
if($all_hokms)
foreach ($all_hokms as $hokm)
{
$one_page_ahkams[] = array(
'hokm_id_inPage' => $hokm['hokm_id_inPage'],
'type' => $page['type'],
);
}
else
$one_page_ahkams[] = array();
$all_pages_data[] = array(
'page_id' => $page['page_id'],
'done' => $page['done'],
'checked' => $page['checked'],
'ahkams' => array($one_page_ahkams), //Here Is the PROBLEM : (((
);
}
else
$all_pages_data[] = array();
echo json_encode($all_pages_data);
如您所见,我想以json格式(从服务器到客户端)发送多维数组(),但是如何更正另一个数组的插入,我的意思是我需要添加{{1} $one_page_ahkams
中的数组一,任何想法
答案 0 :(得分:0)
$one_page_ahkams = array();
$all_pages_data[] = array(
'page_id' => $page['page_id'],
'done' => $page['done'],
'checked' => $page['checked'],
'ahkams' => array($one_page_ahkams);//this comma (,) causes the problem i guess**
);
另一种方法:
$all_pages_data[] = array(
'page_id' => $page['page_id'],
'done' => $page['done'],
'checked' => $page['checked'],
'ahkams' => array(['one_page_ahkams']=>$one_page_ahkams);
);
答案 1 :(得分:-1)
只需输入:'ahkams' => array($one_page_ahkams)
,但请检查$ one_page_ahkams的内容