如何显示来自Codeigniter和mongodb的所有索引数据?

时间:2019-04-29 07:18:45

标签: php codeigniter

我有显示TripUUID的代码。但是它只显示一个数据。代码如下:

function list_of_tripreview(){

        $data = $this->data;
        $arr = [];

$data['list_of_tripreview'] = $this->cms_model->list_of_tripreview();
$TripUUID       = $data['list_of_tripreview'][0]['TripUUID'];
echo json_encode($TripUUID);

此代码在索引TripUUID上给出输出0。如何修改此程序以显示不带[{0]的所有索引数据?

1 个答案:

答案 0 :(得分:1)

您可以使用 foreach loop

$data['list_of_tripreview'] = $this->cms_model->list_of_tripreview();
$datas = $data['list_of_tripreview'];
//$TripUUID = $data['list_of_tripreview'][0]['TripUUID'];

foreach($datas as $key => $item){
    echo $item['TripUUID'].'<br>';
}