Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- testing for array of empty values


penders - 12:11 pm on Feb 20, 2012 (gmt 0)


Just encountered this again... an alternative... if you want to check that an array contains only empty values (that is PHP's definition of empty [uk.php.net]) then you could use array_filter() [uk.php.net], omitting the 2nd (callback) argument. The default behaviour is to filter out empty elements. So, this becomes...

$x = array('',0,0.0,'0',null,false,array()); 
echo !array_filter($x) ? 'EMPTY' : 'NOT empty'; // EMPTY


NB: This does not consider strings of spaces to be empty as in the OP. You would need to provide a simple callback function in order to check for that.


Thread source:: http://www.webmasterworld.com/php/4408603.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com