繁体   English   中英

如何将多个arguments传递给PHP中的匿名function?

[英]How do I pass multiple arguments to an anonymous function in PHP?

PHP 5.3+ 支持匿名函数(尽管在绑定方面,它在 PHP 7.x+ 中对匿名函数的支持略有不同)。 我正在运行 PHP 5.6.x

是否有一种语法允许将多个 arguments传递给匿名 function(不求助于仅使用数组)用作回调 以下哪些例子(如果有的话)在 PHP 中是可能的?

示例 1

function ($str1, $str2 ){   //But, that would be too easy, right?
    return $str1 . $str2;
}

示例 2

function () use ($string, $min, $max) {  // Not seeing this in the manual.
    $length = mb_strlen($string, 'UTF-8');
    return ($length >= $min) && ($length <= $max);
}

示例 3

只是出于好奇,这种形式可能吗?

function ($str1, $str2 ) use ($int1, $int2) { // But, that would be in the manual?
    return $str1 . $str2 .' '. $int2 + $int2;
}

我查看了 PHP 手册,但没有看到我要找的东西。

示例 2 对我有用。

function () use ($string, $min, $max) {  // Not seeing this in the manual.
    $length = mb_strlen($string, 'UTF-8');
    return ($length >= $min) && ($length <= $max);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM