这是什么?
这是关于 PHP 语法时不时出现的问题的集合。这也是一个社区 Wiki,因此邀请每个人参与维护此列表。
为什么是这样?
过去很难找到有关运算符和其他语法标记的问题。
主要思想是提供 Stack Overflow 上现有问题的链接,这样我们就可以更轻松地引用它们,而不是复制 PHP 手册中的内容。
注:自 2013 年 1 月起,Stack Overflow是否支持特殊字符 https://meta.stackexchange.com/questions/160100/a-new-search-engine-for-stack-exchange。只需用引号将搜索词括起来,例如[php] "==" vs "===" https://stackoverflow.com/search?q=%5Bphp%5D%20%22===%22%20vs%20%22==%22
我应该在这里做什么?
如果您因为问了这样的问题而被某人指向这里,请查找下面的特定语法。链接到的页面PHP手册 http://php.net/manual/en/index.php连同链接的问题可能会回答您的问题。如果是这样,我们鼓励您对答案进行投票。此列表并不意味着可以替代其他人提供的帮助。
The List
如果您的特定令牌未在下面列出,您可能会在解析器令牌列表 http://secure.php.net/manual/en/tokens.php.
&
按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php or 参考 http://secure.php.net/manual/en/language.references.php
- 什么时候应该使用按位运算符? https://stackoverflow.com/questions/4705838
-
是否需要在对象前面使用&符号? https://stackoverflow.com/questions/21058439(&$)
=&
参考 http://secure.php.net/manual/en/language.references.php
&=
按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php
&&
逻辑运算符 http://secure.php.net/manual/en/language.operators.logical.php
- PHP - 和/或关键字 https://stackoverflow.com/questions/4502092
%
算术运算符 http://secure.php.net/manual/en/language.operators.arithmetic.php
- PHP 中的百分号是什么意思? https://stackoverflow.com/questions/1934173
- 什么是 PHP 运算符 % 以及如何在实际示例中使用它? https://stackoverflow.com/questions/3204919
!!
逻辑运算符 http://secure.php.net/manual/en/language.operators.logical.php
- PHP 中的双非 (!!) 运算符 https://stackoverflow.com/questions/2127260
@
错误控制运算符 http://secure.php.net/manual/en/language.operators.errorcontrol.php
- PHP中的@符号有什么用? https://stackoverflow.com/questions/1032161
- PHP 中变量名前的“At”符号:@$_POST https://stackoverflow.com/questions/3551527
- PHP 函数和@functions https://stackoverflow.com/questions/3984864
- 我应该在 PHP 代码中使用 @ 吗? https://stackoverflow.com/questions/4872340
- @在PHP中是什么意思? https://stackoverflow.com/questions/3621215
?:
三元运算符 http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
- PHP 运算符“?”是什么?和“:”调用,它们做什么? https://stackoverflow.com/questions/1080247
- PHP 中的 ?: 运算符(“Elvis 运算符”) https://stackoverflow.com/questions/1993409
- 在哪里可以阅读有关用“?”完成的条件的信息。和“:”(冒号)? https://stackoverflow.com/questions/4055355
- 使用 PHP 5.3 ?: 运算符 https://stackoverflow.com/questions/4210187
双问号
??
空合并运算符 https://www.php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op(自 PHP 7 起)
- PHP 中 C# 的空合并运算符 (??) https://stackoverflow.com/questions/7278835
问号后跟类型声明
?string
?int
?array
?bool
?float
可空类型声明 https://www.php.net/manual/en/migration71.new-features.php(自 PHP 7.1 起)
- 如何使用可空类型 https://stackoverflow.com/a/48450841
- 可空返回类型声明 https://stackoverflow.com/a/54217328/250259
?->
问号后跟对象运算符是空安全运算符 https://stackoverflow.com/a/62178856/250259(自 PHP 8.0 起)
- PHP 中有“nullsafe 运算符”吗? https://stackoverflow.com/questions/12351737/is-there-a-nullsafe-operator-in-php
:
控制结构的替代语法 http://secure.php.net/manual/en/control-structures.alternative-syntax.php, 三元运算符 http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary, 返回类型声明 https://www.php.net/manual/en/language.types.declarations.php
- PHP 中的“:”是什么? https://stackoverflow.com/questions/2908095
- PHP 中的“:”是什么意思? https://stackoverflow.com/questions/4747761
- 方法声明后的冒号? https://stackoverflow.com/questions/40346754
::
范围解析运算符 http://secure.php.net/manual/en/language.oop5.paamayim-nekudotayim.php
- PHP 中两个冒号是什么意思? https://stackoverflow.com/questions/2903564
- PHP 令牌名称 T_PAAMAYIM_NEKUDOTAYIM 的含义是什么? https://stackoverflow.com/questions/2588298
- PHP 中 ::(双冒号)和 ->(箭头)有什么区别? https://stackoverflow.com/questions/3173501
- PHP 中的后期静态绑定到底是什么? https://stackoverflow.com/questions/1912902
- 静态::静态函数名() https://stackoverflow.com/questions/4120755
- 意外的 T_PAAMAYIM_NEKUDOTAYIM,需要 T_NS_Separator https://stackoverflow.com/questions/8734823
\
命名空间 http://php.net/namespaces
- PHP 中的反斜杠——它是什么意思? https://stackoverflow.com/questions/10788400
- \(反斜杠)在 PHP (5.3+) 中起什么作用? https://stackoverflow.com/questions/4790020
->
类和对象 http://secure.php.net/manual/en/language.oop5.php
- PHP 运算符“->”叫什么? https://stackoverflow.com/questions/2588149
- PHP 中什么地方使用对象运算符“->”? https://stackoverflow.com/questions/3037526
- PHP 中 ::(双冒号)和 ->(箭头)有什么区别? https://stackoverflow.com/questions/3173501
- PHP 语法 $var1->$var2 是什么意思? https://stackoverflow.com/questions/2316370
- PHP 中的“->”是什么意思? https://stackoverflow.com/questions/4502587
=>
Arrays http://secure.php.net/manual/en/language.types.array.php
- PHP 中的“=>”是什么意思? https://stackoverflow.com/questions/1241819
- PHP 中 => 的使用 https://stackoverflow.com/questions/1655336
- foreach($ex as $k=>$v) 中的 $k => $v 是什么意思? https://stackoverflow.com/questions/4758791
^
按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php
- 按位运算符 XOR ('^') 如何工作? https://stackoverflow.com/questions/2674920
- PHP 中的 ^ 是什么意思? https://stackoverflow.com/questions/2724936
>>
按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php
- >> 在 PHP 中是什么意思? https://stackoverflow.com/questions/2790329
<<
按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php
- PHP 中奇怪的打印行为? https://stackoverflow.com/questions/9718689/strange-print-behaviour-in-php
<<<
赫里多克和现在多克 http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc
- PHP中 https://stackoverflow.com/questions/5539669
- PHP 表达式 https://stackoverflow.com/questions/1048481
- PHP中“ https://stackoverflow.com/questions/3700042
- 在 PHP 中使用 https://stackoverflow.com/questions/2090081
- PHP 中的这种语法是什么? https://stackoverflow.com/questions/2333779
=
赋值运算符 http://secure.php.net/manual/en/language.operators.assignment.php
- 3个不同的等于 https://stackoverflow.com/questions/2063480
==
比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php
- PHP 相等(== 双等于)和恒等(=== 三等)比较运算符有何不同? https://stackoverflow.com/questions/80646
- PHP != 和 == 运算符 https://stackoverflow.com/questions/1663451
- 3个不同的等于 https://stackoverflow.com/questions/2063480
- PHP 中的类型杂耍和(严格)大于/小于比较 https://stackoverflow.com/questions/15813490/
===
比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php
- “= =”是什么意思? https://stackoverflow.com/questions/1117967
- PHP 相等(== 双等于)和恒等(=== 三等)比较运算符有何不同? https://stackoverflow.com/questions/80646
- 3个不同的等于 https://stackoverflow.com/questions/2063480
- PHP 中的类型杂耍和(严格)大于/小于比较 https://stackoverflow.com/questions/15813490/
!==
比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php
- PHP 中的 !== 比较运算符是什么意思? https://stackoverflow.com/questions/1298083
- PHP 中的 !== 和 != 有区别吗? https://stackoverflow.com/questions/1139154
!=
比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php
- PHP != 和 == 运算符 https://stackoverflow.com/questions/1663451
- PHP 中的 !== 和 != 有区别吗? https://stackoverflow.com/questions/1139154
- 比较,!== 与 != https://stackoverflow.com/questions/6356826
- 和 != 有什么区别 https://stackoverflow.com/questions/9671785/what-is-the-difference-between-and
<>
比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php
- PHP 运算符 https://stackoverflow.com/questions/249312
- https://stackoverflow.com/questions/589391 https://stackoverflow.com/questions/589391
- 和 != 有什么区别 https://stackoverflow.com/questions/9671785
- PHP 中的类型杂耍和(严格)大于/小于比较 https://stackoverflow.com/questions/15813490/
<=>
比较运算符 http://secure.php.net/manual/en/language.operators.comparison.php(自 PHP 7.0 起)
- 宇宙飞船(三路比较)算子 https://stackoverflow.com/a/31298778
|
按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php
- | 之间有什么区别?和||运营商? https://stackoverflow.com/questions/2233835
- 使用单个管道“|”有什么作用在函数参数中做什么? https://stackoverflow.com/questions/13811922
||
逻辑运算符 http://secure.php.net/manual/en/language.operators.logical.php
- | 之间有什么区别?和||运营商? https://stackoverflow.com/questions/2233835
- PHP - 和/或关键字 https://stackoverflow.com/questions/4502092
- || 到底是什么?意思是? https://stackoverflow.com/questions/5666741
- PHP 中 or 运算符的行为 https://stackoverflow.com/questions/12213283
~
按位运算符 http://secure.php.net/manual/en/language.operators.bitwise.php
- 这个 ~ 运算符在这里意味着什么? https://stackoverflow.com/questions/1967360
+
算术运算符 http://secure.php.net/manual/en/language.operators.arithmetic.php, 数组运算符 http://secure.php.net/manual/en/language.operators.array.php
- 使用“+”(数组联合运算符)合并两个数组是如何工作的? https://stackoverflow.com/questions/2140090
+=
and -=
赋值运算符 http://secure.php.net/manual/en/language.operators.assignment.php
- += 是做什么用的? https://stackoverflow.com/questions/542995
- 我的 PHP 文档中的 `$page -= 1` 是什么意思? https://stackoverflow.com/questions/7140158
++
and --
自增/自减运算符 http://secure.php.net/manual/en/language.operators.increment.php
- 了解增量 https://stackoverflow.com/questions/1968371
- 回答如下 https://stackoverflow.com/a/3737177
.=
赋值运算符 http://secure.php.net/manual/en/language.operators.assignment.php
- PHP 中 .= 和 += 有什么区别? https://stackoverflow.com/questions/2202331
- PHP 中的 .=(点等于)运算符是什么? https://stackoverflow.com/questions/1241432
.
字符串运算符 http://secure.php.net/manual/en/language.operators.string.php
- 与 echo 和 return 连接时句号和逗号之间的区别? https://stackoverflow.com/questions/1466408
- a 是什么意思? (点)在 PHP 中做什么? https://stackoverflow.com/questions/6484968
,
函数参数 http://php.net/manual/en/functions.arguments.php
- 与 echo 和 return 连接时句号和逗号之间的区别? https://stackoverflow.com/questions/1466408
,
变量声明 http://php.net/manual/en/language.variables.scope.php
- 变量声明中的逗号是什么意思? https://stackoverflow.com/questions/41383218
$$
变量变量 http://php.net/manual/en/language.variables.variable.php
- PHP 中的 $$(美元或双美元)是什么意思? https://stackoverflow.com/questions/2715654
- PHP 中的“$$”是什么 https://stackoverflow.com/questions/4169882
- $函数()和$$变量 https://stackoverflow.com/questions/4891872
`
执行操作符 http://php.net/manual/en/language.operators.execution.php
- 反引号``叫什么? https://stackoverflow.com/questions/6002296
<?=
短开标签 http://php.net/manual/en/ini.core.php#ini.short-open-tag
- PHP中这个符号是什么意思 = https://stackoverflow.com/questions/1963901
- PHP 中“=”是什么意思? https://stackoverflow.com/questions/2020445
- = 是什么意思? https://stackoverflow.com/questions/1959256/what-does-mean
[]
Arrays http://secure.php.net/manual/en/language.types.array.php(自 PHP 5.4 起的短语法)
- PHP 数组...空括号的含义是什么? https://stackoverflow.com/q/20709055/2758197
- 是什么意思 [] https://stackoverflow.com/questions/6933345
- PHP array_push() 与 myArray[] https://stackoverflow.com/questions/2431629
- 从 PHP 数组读取时 [] 是什么意思? https://stackoverflow.com/questions/3908576
- 数组的简写:文字$var = []空数组 https://stackoverflow.com/questions/4271874
<?
开始和结束标签 http://secure.php.net/manual/en/language.basic-syntax.php
- PHP 短标签可以使用吗? https://stackoverflow.com/questions/200640
..
双点字符范围
- 允许双点范围语法的本机 PHP 函数 https://stackoverflow.com/q/72865138/2943403
...
参数解包 http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list(自 PHP 5.6 起)
**
求幂 http://secure.php.net/manual/en/migration56.new-features.php#migration56.new-features.exponentiation(自 PHP 5.6 起)
#
一行 shell 风格的注释 http://php.net/manual/en/language.basic-syntax.comments.php
- 我可以在 PHP 中使用哈希值进行注释吗? https://stackoverflow.com/questions/9093609/can-i-use-hashes-for-comments-in-php
#[]
属性 https://stackoverflow.com/a/71641821/6660678(自 PHP 8 起)