欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

菜鸟,json输出

程序员文章站 2022-05-30 16:59:27
...
foreach ($query->result_array() as $row)   {	$data = array(		'id' =>  $row['id'],		'title' =>$row['title']	);   }echo json_encode($data);

前端为何只输了一组数据?
CI框架
({"id":"2","title":"\u65b0\u7586VS\u5317\u4eac"})


回复讨论(解决方案)

foreach ($query->result_array() as $row)
{
$data[] = array(
'id' => $row['id'],
'title' =>$row['title']
);
}

foreach ($query->result_array() as $row)
{
$data[] = array(
'id' => $row['id'],
'title' =>$row['title']
);
}


多谢!