4 回答
TA贡献1963条经验 获得超6个赞
$array = [
{
"pid": "1",
"pname": "Burger",
"price": "20",
"qnty": "1",
"pimg": "1.jpg"
},
{
"pid": "2",
"pname": "Cheese burger",
"price": "30",
"qnty": "1",
"pimg": "2.jpg"
}
]
你可以使用isset功能。
$key = 1;
$count =0 ;
foreach($array as $a) {
if(isset(array_search($key,$a))){
//your logic to execute if the $key is there in the array
$count ++;
}
}
if($count==0){
//add to cart logic
}
TA贡献1829条经验 获得超7个赞
您需要使用循环迭代数组,然后根据数组的任何索引检查值
foreach ($items as $item){
if($item->pid == 1) {
// do whatever you want to do
}
}
TA贡献1827条经验 获得超8个赞
您可以利用isset()和!empty()
foreach($lists as $list) {
if(isset($list['pid']) && (!empty($list['pid']))) { // this will check if a key exists. If yes, then check for it's value. If value is there, then true
// pid exists and has a value
} else {
}
}
- 4 回答
- 0 关注
- 156 浏览
添加回答
举报