This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
=>运算符在以下代码中的含义是什么?
foreach ($user_list as $user => $pass)
Run Code Online (Sandbox Code Playgroud)
该代码是PHP.net上的评论.用户没有指定的值$user_list,$user或$通过.我通常认为这=>意味着等于或大于.
但是,我不确定它的用途,因为它没有分配.我把代码读成了
以上对我没有意义.
我试图理解这意味着什么:
foreach($this->domains as $domain=>$users) {
// some code...
}
Run Code Online (Sandbox Code Playgroud)
我知道$this->domains是一个foreach将索引的数组。但是是什么as $domain=>$users意思呢?我只见过=>在数组中使用的运算符来设置 (key, value) 对。该类有一个名为 的成员$domain,但我认为它将作为$this->domain.
我了解PHP 7.4中的箭头功能。我尝试像这样使用它们
<?php
$num = 1;
$arrowfunction = () => {
return $num + 1;
}
echo $arrowfunction();
Run Code Online (Sandbox Code Playgroud)
因为我=>在拉取请求中看到了运算符。就像JavaScript。
我希望输出为“ 2”,但这没有用!我有
解析错误:语法错误,第3行/test.php中出现意外的')'