我想檢查給定值是否存在於數組中。 這裏我有一個函數,我將傳遞一個值作爲參數。 我有一個陣列$_SESSION['cart']
在那裏我已經存儲了多個值,而迭代陣列我想檢查的product_id是在陣列如何檢查數組中是否存在給定值
我打電話功能的同時遍歷數組檢查的product_id存在
<?php
foreach($_SESSION['cart'] as $item):
getCartitems($item);
endforeach;
?>
功能
function productIncart($product_id){
//check if the $_SESSION['cart']; has the given product id
//if yes
//return true
//else
//return false
}
我該怎麼做?
你的數據是如何在$ _SESSION ['cart']'中構造的? – vitozev