|  | Posted by ZeldorBlat on 02/12/06 00:55 
Dave Mennenoh wrote:> ...good one-liner...
 >
 > This is what I came up with:
 >
 > function isEmpty($array){
 >   return (count(array_filter($array)) == 0) ? 1 : 0;
 >  }
 >
 > returns 1 if all elements are "" otherwise it returns 0.
 >
 >
 > --
 > Dave -
 > www.blurredistinction.com
 > www.macromedia.com/support/forums/team_macromedia/
 
 It really depends on what the OP means by "empty."  The code above will
 return 1 if the array only contains elements that evaluate to false.
 Examples of things that evaluate to false: false, "", 0, null.  So,
 given the array (0, 0, 0) that function will return true.
 
 If your definition of "empty" is really the empty string, you can make
 a small change to Dave's function as such:
 
 function isEmpty($array) {
 $my_not_empty = create_function('$v', 'return strlen($v) > 0;');
 return (count(array_filter($array, $my_not_empty)) == 0) ? 1 : 0;
 }
 [Back to original message] |