empty()不是有效的回调? [英] empty() not a valid callback?
本文介绍了empty()不是有效的回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在php中的数组映射中使用empty()。我收到错误,它不是一个有效的回调。
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
这应该不行吗?
长的故事:我试图(太?)聪明,并检查所有的数组值不是空字符串。
Long story: I'm trying to be (too?) clever and checking that all array values are not empty strings.
推荐答案
这是因为 empty
是一个语言结构而不是函数。从空白()中的手册:
It's because empty
is a language construct and not a function. From the manual on empty():
注意:因为这是一个语言结构而不是函数,所以不能使用变量函数调用
Note: Because this is a language construct and not a function, it cannot be called using variable functions
这篇关于empty()不是有效的回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文