how to get single value from array in codeigniter

前端 未结 2 1842
我寻月下人不归
我寻月下人不归 2021-01-23 06:44

I stored some data to an array using this code

$this->data[\'result\']    =   $this->mymodel->search($keyword);

when I print my result

相关标签:
2条回答
  • 2021-01-23 06:46

    If your model returns only one record, you can use this shortcut:

    $pro_id = $this->data['result'][0]->product_id;

    0 讨论(0)
  • 2021-01-23 06:59

    Try this:

     $pro_id = [];
    
     foreach($this->data['result'] as $key => $val){
        $pro_id[] = $val->product_id;
     }
    
     print_r($pro_id);
    
    0 讨论(0)
提交回复
热议问题