Jump to content

Checking if an item is in an array - using in_array but not working as expected


tec-4

Recommended Posts

Hello,

 

Currently have an array like looks like the following when using print_r($session->items):

 

Array ( [F1225] => 1 [EDS11147317] => 1 [1156D6RE001] => 1 [i111ADE47946] => 1 [s679AQ339] => 1 [s67914599] => 1 [CH111337631254] => 1 [s6787903647] => 1 [A11144O189] => 1 [F11144520] => 1 [121584Q12] => 1 [i11144661ADE] => 1 [s678829NB] => 1 )

 

I am trying to check if an item is in the array and if so, display a different result but currently every item says it is in the array when they are not (unless my logic is off...from the items I am looking at some should be included and some should not..but the below code is showing every item as having the same result).

 

Example:

 

foreach ($items as $item) {

 

if (in_array($item->ItemID, $session->items))  {  //$session->items is the array output above

 

    echo "In Array";

 

    } else {

 

    echo "NOT in Array";

 

    }

 

}

 

 

Currently everything say "In Array" when some should not.  Am I using the in_array incorrectly?

 

Thanks Everyone.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.