I want to check that an array has no values or that the values in the array are empty. Can someone explain how to do this?
我想检查一个数组没有值或数组中的值是否为空。有人可以解释如何做到这一点?
2 个解决方案
#1
18
Someday I've learned very smart solution here on SO
总有一天,我在SO上学到了非常聪明的解决方案
if(!array_filter($array)) {
//array contains only empty values
}
or even smarter one (if applicable):
甚至更聪明的(如果适用):
if(!array_filter($array,'trim')) {
//array contains only empty values
}
#2
11
You want the empty()
function, here's the documentation of the empty function http://php.net/manual/en/function.empty.php
你想要empty()函数,这里是空函数的文档http://php.net/manual/en/function.empty.php
#1
18
Someday I've learned very smart solution here on SO
总有一天,我在SO上学到了非常聪明的解决方案
if(!array_filter($array)) {
//array contains only empty values
}
or even smarter one (if applicable):
甚至更聪明的(如果适用):
if(!array_filter($array,'trim')) {
//array contains only empty values
}
#2
11
You want the empty()
function, here's the documentation of the empty function http://php.net/manual/en/function.empty.php
你想要empty()函数,这里是空函数的文档http://php.net/manual/en/function.empty.php