views:

40

answers:

2

I have this array:

$items_pool = Array ( 
[0] => Array ( [id] => 1 [quantity] => 1 ) 
[1] => Array ( [id] => 2 [quantity] => 1 ) 
[2] => Array ( [id] => 72 [quantity] => 6 ) 
[3] => Array ( [id] => 4 [quantity] => 1 )
[4] => Array ( [id] => 5 [quantity] => 1 ) 
[5] => Array ( [id] => 7 [quantity] => 1 ) 
[6] => Array ( [id] => 8 [quantity] => 1 ) 
[7] => Array ( [id] => 9 [quantity] => 1 ) 
[8] => Array ( [id] => 19 [quantity] => 1 ) 
[9] => Array ( [id] => 20 [quantity] => 1 ) 
[10] => Array ( [id] => 22 [quantity] => 1 ) 
[11] => Array ( [id] => 29 [quantity] => 0 ) 
) 

I'm trying to loop through this array and perform a conditional based on $items_pool[][id]'s value. I want to then report back TRUE or NULL/FALSE, so I'm just testing the presence of to be specific.

+1  A: 

Loop through an check if anything is empty..

foreach($items_pool as $arr){
   echo $arr['id'].'==>'.$arr['quantity'];
   if($arr['quantity'] == 0){
      echo 'id:'.$arr['id'].' is empty!';
      return false;
   }
}
PHP_Jedi
+2  A: 

Something like this:

$items_pool = array(...);
$result = false;

foreach ($items_pool as $item) {
    if ('something' == $item['id']) {
        $result = true;
    }
}
Crozin