2

我有一些这样的数组:-

$atts = [
    "images_url" => "1",
    "link_list" => "2",
];

但有时数组可能是这样的:-

$atts = [
    "images_url" => "1"
];

或者首先可以是空的,它不是空的吗?我需要一些额外的逻辑,如何检查数组的某个值是否不为空或存在并做一些额外的逻辑?

4

1 回答 1

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

于 2017-02-01T17:52:51.000 回答