empty() not a valid callback?

Posted by user151841 on Stack Overflow See other posts from Stack Overflow or by user151841
Published on 2010-04-08T19:54:17Z Indexed on 2010/04/08 20:03 UTC
Read the original article Hit count: 289

Filed under:
|
|

I'm trying to use empty() in array mapping in php. I'm getting errors that it's not a valid callback.

$ cat test.php
<?

$arrays = array(
   'arrEmpty' => array(
        '','',''
    ),
);

foreach ( $arrays as $key => $array ) {

        echo $key . "\n";
        echo array_reduce( $array, "empty" );
        var_dump( array_map("empty", $array) );
        echo "\n\n";

}

$ php test.php
arrEmpty

Warning: array_reduce(): The second argument, 'empty', should be a valid callback in /var/www/authentication_class/test.php on line 12

Warning: array_map(): The first argument, 'empty', should be either NULL or a valid callback in /var/www/authentication_class/test.php on line 13
NULL

Shouldn't this work?

Long story: I'm trying to be (too?) clever and checking that all array values are not empty strings.

© Stack Overflow or respective owner

Related posts about php

Related posts about array-map