how to get single value from array in codeigniter

14,641

Try this:

 $pro_id = [];

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

 print_r($pro_id);
Share:
14,641
Udara Suranga
Author by

Udara Suranga

In my university life I hate web developing. but now I love developing.

Updated on June 04, 2022

Comments

  • Udara Suranga
    Udara Suranga almost 2 years

    I stored some data to an array using this code

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

    when I print my result by using print_r($this->data);

    it shows like this

    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 ) ) )
    

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