Arrays 检查并比较关联数组值与in_数组?
我正在尝试使用Arrays 检查并比较关联数组值与in_数组?,arrays,session,associative-array,Arrays,Session,Associative Array,我正在尝试使用in_array函数检查第二个数组中是否存在值。我想从以下数组中搜索556729685: $_SESSION["cart_item"] = Array ( [cart_item] => Array ( [0] => Array ( [product_name] => White Sakura Necktie
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"]));
没有一个有效,请帮助我解决此问题。关联数组由键、列和值组成。所以,为了检查值的存在性,需要到达数组的键
for($i=0;$i<count($_SESSION["cart_item"]);$i++)
{
if( in_array( 556729685 ,$_SESSION["cart_item"][$i] ) )
{
echo "exist in id:".$i.'<br/>';
}
}
$i=0;$i的