0

这是我的一段代码:

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 格式(从服务器到客户端)发送多维数组(),但是如何更正将数组插入另一个数组,我的意思是我需要$one_page_ahkams在一个数组中添加数组$all_pages_data,任何想法

4

2 回答 2

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);
);
于 2013-08-25T12:56:59.843 回答
-1

只是说: 'ahkams' => array($one_page_ahkams),但检查 $one_page_ahkams 的内容

于 2013-08-25T13:02:53.443 回答