检查关联数组值并将其与 in_array 进行比较?

check and compare associative array value with in_array?

我正在尝试使用 in_array 函数来检查值是否存在于第二个数组中。我想从以下数组中搜索 556729685:

$_SESSION["cart_item"] =

Array
( 
    [cart_item] => Array 
        ( 
            [0] => Array 
                ( 
                    [product_name] => White Sakura Necktie
                    [id] => 11
                    [product_auto_id] => 556729685
                    [quantity] => 2
                    [product_regular_price] => 95
                    [product_sale_price] => 95
                    [product_image] => 556729680Black_Sakura_Necktie.jpg 
                )
            [1] => Array 
                ( 
                    [product_name] => hhhad ba bhdbh
                    [id] => 10
                    [product_auto_id] => 951790801
                    [quantity] => 2
                    [product_regular_price] => 20
                    [product_sale_price] => 
                    [product_image] => 951790801hhhad_ba_bhdbh_.jpg 
                )
        ) 
)

我正在使用以下函数进行检查,但输出错误:

in_array(556729685, array_keys($_SESSION["cart_item"]));

我也试过这个:

in_array(556729685, array_values($_SESSION["cart_item"]));

None 正在处理,请帮我解决这个问题。

关联数组由键、列和值组成。因此,为了检查值是否存在,您需要到达数组的键。

for($i=0;$i<count($_SESSION["cart_item"]);$i++)
{
     if( in_array( 556729685 ,$_SESSION["cart_item"][$i] ) )
    {
      echo "exist in id:".$i.'<br/>';
    }
}