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?
How do I determine if an array is empty in PHP?
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
}
@Vinay it seems empty() is better anyway –
Hindsight
but empty gives me that array has values –
Silvern
@Vinay what PHP version you're using? –
Hindsight
in local machine php 5 and in server its php 4 –
Silvern
array_filter is really handy! never used it before today, but it solves my problem! thank you! –
Rodd
You want the empty()
function, here's the documentation of the empty function http://php.net/manual/en/function.empty.php
© 2022 - 2024 — McMap. All rights reserved.
is_array
,count
,empty
,isset
. It all depends on what exactly you're trying to test. – Huarache