PHP中三点(...)的含义 [英] Meaning of Three dot (...) in PHP
问题描述
PHP中的三点(...)是什么意思?
What is the meaning of Three dot (...) in PHP ?
当我在服务器中安装Magento 2时,出现错误.检查代码,发现有一个三点(...),这会产生错误.我在下面提到了代码
While I am installing Magento 2 in my Sever I got an error. Investigate the code and found that there is a Three dot (...), which is producing the error. I mentioned the code below
return new $type(...array_values($args));
推荐答案
...$str
被称为此功能允许您捕获函数可变数量的参数,并根据需要传递传入的普通"参数.举个例子最容易看到:
This feature allows you to capture a variable number of arguments to a function, combined with "normal" arguments passed in if you like. It's easiest to see with an example:
function concatenate($transform, ...$strings) {
$string = '';
foreach($strings as $piece) {
$string .= $piece;
}
return($transform($string));
}
echo concatenate("strtoupper", "I'd ", "like ", 4 + 2, " apples");
// This would print:
// I'D LIKE 6 APPLES
函数声明中的参数列表中包含...
运算符,它的基本含义是"...,其他所有内容都应放入$ strings中".您可以向该函数传递2个或更多参数,第二个及后续参数将添加到$ strings数组中,可供使用.
The parameters list in the function declaration has the ...
operator in it, and it basically means " ... and everything else should go into $strings". You can pass 2 or more arguments into this function and the second and subsequent ones will be added to the $strings array, ready to be used.
希望这会有所帮助!
这篇关于PHP中三点(...)的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!