字母索引的數組的就是花括號,數字索引纔是中括號,好比:json
數字索引的數組示例:數組
$p = array('name'=>'yu','age'=>'23'); $data[0]['name']='zhangsan'; $data[0]['orderDate']='2018-02'; $data[0]['price']='58'; $data[0]['prodcut'][0]['prodcut_id']='101'; $data[0]['prodcut'][0]['prodcut_price']='28'; $data[0]['prodcut'][0]['prodcut_name']='毛巾'; $data[0]['prodcut'][1]['prodcut_id']='102'; $data[0]['prodcut'][1]['prodcut_price']='30'; $data[0]['prodcut'][1]['prodcut_name']='浴巾'; $data=json_encode($data); echo $data; exit; //結果以下: [{"name":"zhangsan","orderDate":"2018-02","price":"58","prodcut":[{"prodcut_id":"101","prodcut_price":"28","prodcut_name":"u6bdbu5dfe"},{"prodcut_id":"102","prodcut_price":"30","prodcut_name":"u6d74u5dfe"}]}]
字母索引的數組示例:code
$p = array('name'=>'yu','age'=>'23'); $data=json_encode($p); echo $data; exit; //結果以下: {"name":"yu","age":"23"}