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 Answers
Someday I've learned very smart solution here on 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
}
5 Comments
Your Common Sense
@Vinay it seems empty() is better anyway
n92
but empty gives me that array has values
Your Common Sense
@Vinay what PHP version you're using?
n92
in local machine php 5 and in server its php 4
AO_
array_filter is really handy! never used it before today, but it solves my problem! thank you!
You want the empty() function, here's the documentation of the empty function http://php.net/manual/en/function.empty.php
is_array,count,empty,isset. It all depends on what exactly you're trying to test.