dongyun6835 2015-11-13 16:24
浏览 23

php无法传递函数作为参数? [重复]

This question already has an answer here:

Works: returns [false,null]

array_filter([1, 2, 3, false, null], function($value) {
   return empty($value);
});

Does not Work:

array_filter([1, 2, 3, false, null], empty); // syntax error, unexpected ')',expecting '('

Why cant i just pass in the function as an argument?

</div>
  • 写回答

3条回答 默认 最新

  • dsafgdafgdf45345 2015-11-13 16:31
    关注

    empty() is not a function, it's a language construct. array_filter expects a callable as the second argument. You will need to use a wrapper function exactly as you have in your first example:

    array_filter([1, 2, 3, false, null], function($value) {
       return empty($value);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计