php json數組問題

來源:互聯網
上載者:User
php json數組問題,$result1和$result2兩個數組合并成一個,單獨輸出 echo json_encode($result1); echo json_encode($result2);
最後輸出效果:
{
“id”:”111”,
“image_name”:”我的臥室“,
“image_url”:“d:/image/a.png”,

comments:[{
“uid”,“122”,
“cname“:”小明“,
“ctime”,“2014-12-12”,
}]
}
做出這種效果, echo json_encode( array($result1, $result2) );這樣輸出的不對,是直接在後面加上了,而沒有成單獨的數組

該怎麼做呢


回複討論(解決方案)

你的 $result1、$result2 都是什嗎?

單獨的數組是什麼樣的,貼出最後結果看看。

echo json_encode( array(array("content"=>$result1), $result2) ) 是這樣?

$result1 和 $result2 都?有?出。

echo json_encode(array_merge($result1, array("comments"=>$result2))) 這樣??

你的 $result1、$result2 都是什嗎?


$result 1 就是“id”:”111”,
“image_name”:”我的臥室“,
“image_url”:“d:/image/a.png”,
這些,
$result 2

單獨的數組是什麼樣的,貼出最後結果看看。


單獨的就是“id”:”111”,
“image_name”:”我的臥室“,
“image_url”:“d:/image/a.png”,
後面的是$result2

$result1 和 $result2 都?有?出。


$result1就是上半部,$result2就是下半部

$result1 = array(  'id' => 111,  'image_name' => '我的臥室',  'image_url' => 'd:/image/a.png',);$result2 = array(  'comments' => array(    array(      'uid' => 122,      'cname' => '小明',      'ctime' => '2014-12-12',    ),  ),);echo json_encode(array_merge($result1, $result2));

$result1 = array('id' => '111','image_name' => '我的臥室','image_url' => 'd:/image/a.png');$result2 = array('comments' => array(array('uid' => '122','cname' => '小明','ctime' => '2014-12-12')));$result = array_merge($result1, $result2);echo json_encode($result);

我覺得樓主的問題似乎沒有那麼簡單,給兩個數組讓你調用函數嗎?
我看了半天問題就是沒看懂意思.

我覺得樓主的問題似乎沒有那麼簡單,給兩個數組讓你調用函數嗎?
我看了半天問題就是沒看懂意思.


就是有兩個數組,把他們輸出成一個json數組
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.