PHP支持可变长度参数函数。这意味着你可以在函数中传递0、1或n个参数。为此, 你需要在参数名称之前使用3个椭圆(点)。
自PHP 5.6起, 为可变长参数实现了3点概念。
让我们看一个简单的PHP可变长度参数函数示例。
<?php
function add(...$numbers) {
$sum = 0;
foreach ($numbers as $n) {
$sum += $n;
}
return $sum;
}
echo add(1, 2, 3, 4);
?>
输出
10
来源:
https://www.srcmini02.com/29419.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_37953.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57