在我的服务器上安装 Magento 2 时,出现错误。查了代码,发现有三个点(...
),就是报错。我包含了我在下面找到的代码:
return new $type(...array_values($args));
这个操作符叫什么,它的用途是什么?
最佳答案
这实际上被称为 ...
operator in PHP , 但在其他语言中称为 splat 运算符。来自 a 2014 LornaJane blog post关于功能:
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");
(这将打印 I'D LIKE 6 APPLES
)
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 $stringsarray
, ready to be used.
关于php - PHP中三个点(...)是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41124015/