function countproduct(){
$count = 0;
$cart = isset($_SESSION['cart']) ? $_SESSION['cart']:array();
foreach($cart as $row):
if($row['qty']!=0){
$count = $count + 1;
}
endforeach;
return $count;
我想知道什么意思?在isset之后($ _ SESSION [' cart'])
答案 0 :(得分:1)
这是一个三元运算符,这些行:
$cart = isset($_SESSION['cart']) ? $_SESSION['cart']:array();
可以转换为:
if (isset($_SESSION['cart'])) {
$cart = $_SESSION['cart'];
} else {
$cart = array();
}
有关详细信息,请查看php operations documentation