如何从codeigniter中的数组中获取单个值

时间:2015-08-26 08:04:08

标签: php mysql arrays codeigniter

我使用此代码

将一些数据存储到数组中
$this->data['result']    =   $this->mymodel->search($keyword);

使用print_r($this->data);

打印结果时

它显示如下

Array ( [base_url] => http://localhost/pelikanartline.com/ [result] => Array ( [0] => stdClass Object ( [product_id] => 2 [product_code] => 167007 [product_name] => ARTLINE VIVIX HIGHLIGHTERS 10PK YELLOW [product_discription] => some description [xylene_free] => y [rohs_compliant] => y [product_features] => some text ) ) )

现在我想将product_id值存储到像pro_id这样的变量中。请帮我这样做。

1 个答案:

答案 0 :(得分:0)

试试这个:

 $pro_id = [];

 foreach($this->data['result'] as $key => $val){
    $pro_id[] = $val->product_id;
 }

 print_r($pro_id);