php in_array() inside a foreach

Posted by 432skronker on Stack Overflow See other posts from Stack Overflow or by 432skronker
Published on 2012-12-14T04:38:48Z Indexed on 2012/12/14 5:03 UTC
Read the original article Hit count: 81

Filed under:
|
|

I am having issues with using in_array() inside a foreach loop. Not sure if this is even possible or if I am doing something ridiculous where there are better ways. What I want to do is go through all the items and if their item id matches one thats in the array, return true and add the price of the item to a runninng total.

$price = 0;
$result = false;
$array = array(1533, 2343, 2333);

foreach($order['items'] as $item){
  if(in_array($item['Item'], $array)){
     $result = true;
     $price += $item['Price'];
  }
}

**UPDATED**
Here is the order array

[items] => Array
    (
        [0] => Array
            (
                [Item] => 139957
                [OrderID] => 16025
                [SizeID] => 24
                [Price] => 46.00
            )

        [1] => Array
            (
                [Item] => 2343
                [OrderID] => 16025
                [SizeID] => 12
                [Price] => 32.00
            )
    )

[data] => Array
    (
    )

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays