Php 找出会话中的数组键已存在
我有这样的课程Php 找出会话中的数组键已存在,php,Php,我有这样的课程 $id = 'A001' $_SESSION['cart'][$id] 它包含如下所示的值 Array ( [A001] => Array ( [path] => product-details.html [img] => images/product/3.jpg [size] => 12 x 1.5 L [price] => 8
$id = 'A001'
$_SESSION['cart'][$id]
它包含如下所示的值
Array
(
[A001] => Array
(
[path] => product-details.html
[img] => images/product/3.jpg
[size] => 12 x 1.5 L
[price] => 8.8
[quantity] => 1
[total] => 8.8
)
)
如何确定此$u会话['cart'][id是否存在]?
isset($_SESSION['cart'][$id])
这将为您提供一个布尔值,指示是否设置了变量
它总是返回true如果未设置,则不会返回true。
if (isset($_SESSION['cart'][$id])) {
// its set...
}