0

I have a following array:

array(4){ 
[0]=> array(4){ 
["id"]=> int(1) 
["item_name"]=> string(8) "Oilspill" 
["requests_count"]=> int(0) 
["item_information"]=> string(21) "Just some spilled oil"
} 
[1]=> array(4){ 
["id"]=> int(2) 
["item_name"]=> string(3) "Fan" 
["requests_count"]=> int(0) 
["item_information"]=> string(12) "Standart fan" 
}
[2]=> array(4){ 
["id"]=> int(3) 
["item_name"]=> string(12) "Green candle" 
["requests_count"]=> int(0) 
["item_information"]=> string(16) "Smells like moss"
}
[3]=> array(4){ 
["id"]=> int(4) 
["item_name"]=> string(8) "Yin Yang" 
["requests_count"]=> int(0) 
["item_information"]=> string(22) "Ancient Chinese symbol"
} 

Is it possible to select an entire array that contains the id value I'm looking for?

For example: I want an item with id=2, the output would be:

[1]=> array(4){ 
["id"]=> int(2) 
["item_name"]=> string(3) "Fan" 
["requests_count"]=> int(0) 
["item_information"]=> string(12) "Standart fan" 
}

1 Answers1

0

Yes, you can. Loop through all of your rows, then look for the id value of 2.

//outer loop
foreach($array as $row){

    //inner condition
    if($row['id'] == 2){
        //do what you need with this value
    } 
}
//...
Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29