如何从Codeigniter中的数组中获取单个值 [英] how to get single value from array in codeigniter

查看:87
本文介绍了如何从Codeigniter中的数组中获取单个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码将一些数据存储到了一个数组

I stored some data to an array using this code

$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这样的变量中.请帮助我做到这一点.

now I want to store product_id value to a variable like pro_id. please help me to do this.

推荐答案

尝试一下:

 $pro_id = [];

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

 print_r($pro_id);

这篇关于如何从Codeigniter中的数组中获取单个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆