我有一些像这样的数组: -
$atts = [
"images_url" => "1",
"link_list" => "2",
];
但有时数组可能是这样的: -
$atts = [
"images_url" => "1"
];
或者首先可以是空的,因为它不是空的我需要一些额外的逻辑,如何检查数组的某些值是否为空或存在并做一些额外的逻辑?
答案 0 :(得分:1)
你可以这样做: -
if(count($atts) > count(array_filter($atts))){
echo "some indexes are empty";
}
实施例: - https://eval.in/728563
评论中的另一个问题
foreach($atts as $key=>$val){
if(!empty($atts[$key])){ // will check both index exist and have some value
echo $val;
}
}
输出: - https://eval.in/728568