参考——这个符号在 PHP 中是什么意思? [英] Reference — What does this symbol mean in PHP?
问题描述
这是什么?
这是一个不时出现的关于 PHP 语法的问题集合.这也是一个社区维基,所以邀请大家参与维护这个列表.
这是为什么?
过去很难找到有关运算符和其他语法标记的问题.¹
主要思想是在 Stack Overflow 上提供指向现有问题的链接,这样我们就可以更轻松地引用它们,而不是从 PHP 手册中复制内容.
注意:自 2013 年 1 月起,Stack Overflow 确实支持特殊字符.只需用引号将搜索词括起来,例如[php] "==》对比==="
我应该在这里做什么?
如果有人指出您是因为您提出了这样的问题,请在下面找到特定的语法.PHP 手册 的链接页面以及链接的问题很可能会回答您的问题.如果是这样,我们鼓励您对答案投赞成票.此列表不能替代其他人提供的帮助.
名单
如果您的特定令牌未在下面列出,您可能会在解析器列表中找到它令牌.
- 用 & 符号启动 PHP 函数是什么意思?
- 了解 PHP &(与号,按位与)运算符
- PHP&";操作员
- & 之间的区别和&&在 PHP 中
- 什么是&"?在 PHP 中是指这里吗?
- 什么是&"?在这种情况下是什么意思?
- 什么是&"?PHP中的符号是什么意思?
- PHP 中的此签名 (&) 是什么意思?
- &"如何?运算符在 PHP 函数中工作?
- 什么是&&2 在 PHP 中是什么意思?
- 什么时候应该使用位运算符?
- 是否需要在对象前使用 & 符号? (&$)
=&
参考资料
&=
位运算符一个>
&&
逻辑运算符
%
算术运算符
!!
逻辑运算符
@
错误控制运算符
?:
三元运算符
??
空合并运算符(自 PHP 7 起)
?string
?int
?array
?bool
?float
可空返回类型声明(自 PHP 7.1 起)
::
范围解析运算符
- PHP 中的两个冒号是什么意思?
- PHP 令牌名称 T_PAAMAYIM_NEKUDOTAYIM 的含义是什么?
- ::(双冒号)和 -> 之间的区别是什么?(箭头)在 PHP 中?
- PHP 中的后期静态绑定到底是什么?
- static::staticFunctionName()
- 意外的 T_PAAMAYIM_NEKUDOTAYIM,期待 T_NS_Separator
\
命名空间
->
类和对象
- 什么是->"?PHP 运算符调用?
- 我们在哪里使用对象运算符->"?在 PHP 中?
- ::(双冒号)和 -> 之间的区别是什么?(箭头)在 PHP 中?
- PHP 语法 $var1->$var2 是什么意思?
- 什么是->"?在 PHP 中是指/指代吗?
=>
数组
^
位运算符
>>
位运算符
<<
位运算符
<<<
Heredoc 或 Nowdoc
=
赋值运算符
==
比较运算符
===
比较运算符一个>
!==
比较运算符一个>
!=
比较运算符
<>
比较运算符
<=>
比较运算符(自 PHP 7.0 起)
|
位运算符
||
逻辑运算符
~
位运算符
+=
和 -=
赋值运算符
++
和 --
递增/递减运算符
.=
赋值运算符
.
字符串运算符
,
函数参数
,
变量声明>
$$
变量变量
`
执行运算符>
<?=
短打开标签
[]
数组(自 PHP 5.4 起的简短语法)
<?
开始和结束标签
...
参数解包(自 PHP 5.6 起)
**
求幂(自 PHP 5.6 起)
#
单行外壳样式评论
?->
NullSafe 操作符调用(自 PHP 8.0 起)
++
增量运算符
--
递减运算符
示例名称效果---------------------------------------------------------------------++$a Pre-increment 将 $a 增加 1,然后返回 $a.$a++ 后增量返回 $a,然后将 $a 加一.--$a Pre-decrement 将 $a 减一,然后返回 $a.$a-- 递减后返回 $a,然后将 $a 减一.
这些可以在变量之前或之后.
如果放在变量之前,则先对变量进行递增/递减操作,然后返回结果.如果放在变量之后,则变量先返回,然后进行递增/递减操作.
例如:
$apples = 10;for ($i = 0; $i <10; ++$i) {回声我有".$apples-- ." 苹果.我只吃了一个.\n";}
在上面的例子中使用 ++$i
,因为它更快.$i++
会得到相同的结果.
预增量稍微快一点,因为它确实增加了变量,然后返回"了结果.后增量创建一个特殊变量,在那里复制第一个变量的值,只有在第一个变量被使用后,才用第二个变量替换它的值.
但是,您必须使用$apples--
,因为首先您要显示当前的苹果数量,然后然后要从中减去一个.
您也可以在 PHP 中递增字母:
$i = "a";而 ($i < "c") {回声 $i++;}
一旦到达z
,下一个是aa
,依此类推.
请注意,字符变量可以递增但不能递减,即使如此,也仅支持纯 ASCII 字符(a-z 和 A-Z).
<小时>
堆栈溢出帖子:
What is this?
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.
Why is this?
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 the PHP Manual.
Note: Since January 2013, Stack Overflow does support special characters. Just surround the search terms by quotes, e.g. [php] "==" vs "==="
What should I do here?
If you have been pointed here by someone because you have asked such a question, please find the particular syntax below. The linked pages to the PHP manual along with the linked questions will likely answer your question then. If so, you are encouraged to upvote the answer. This list is not meant as a substitute for the help others provided.
The List
If your particular token is not listed below, you might find it in the List of Parser Tokens.
&
Bitwise Operators or References
- What does it mean to start a PHP function with an ampersand?
- Understanding PHP & (ampersand, bitwise and) operator
- PHP "&" operator
- Difference between & and && in PHP
- What does "&" mean here in PHP?
- What does "&" mean in this case?
- What does the "&" sign mean in PHP?
- What does this signature mean (&) in PHP?
- How does the "&" operator work in a PHP function?
- What does & in &2 mean in PHP?
- When should I use a bitwise operator?
- Is there ever a need to use ampersand in front of an object? (&$)
=&
References
- Reference assignment operator in PHP, =&
- What do the "=&" and "&=" operators in PHP mean?
- What do the '&=' and '=&' operators do?
- What does =& mean in PHP?
- 'AND' vs '&&' as operator
- Difference between & and && in PHP
- Is there any difference between "and" and "&&" operators in PHP?
- PHP - and / or keywords
- What does the percent sign mean in PHP?
- What is the PHP operator % and how do I use it in real-world examples?
- What is the use of the @ symbol in PHP?
- 'At' symbol before variable name in PHP: @$_POST
- PHP functions and @functions
- Should I use @ in my PHP code?
- What does @ mean in PHP?
- What are the PHP operators "?" and ":" called and what do they do?
- ?: operator (the 'Elvis operator') in PHP
- Where can I read about conditionals done with "?" and ":" (colon)?
- Using PHP 5.3 ?: operator
??
Null Coalesce Operator (since PHP 7)
?string
?int
?array
?bool
?float
Nullable return type declaration (since PHP 7.1)
:
Alternative syntax for control structures, Ternary Operator, Return Type Declaration
- What do two colons mean in PHP?
- What's the meaning of the PHP token name T_PAAMAYIM_NEKUDOTAYIM?
- What's the difference between :: (double colon) and -> (arrow) in PHP?
- What exactly are late static bindings in PHP?
- static::staticFunctionName()
- Unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_NS_Separator
- What is the "->" PHP operator called?
- Where do we use the object operator "->" in PHP?
- What's the difference between :: (double colon) and -> (arrow) in PHP?
- What does the PHP syntax $var1->$var2 mean?
- What does "->" mean/refer to in PHP?
=>
Arrays
- What does <<<END mean in PHP?
- PHP expression <<<EOB
- In PHP, what does "<<<" represent?
- Using <<<CON in PHP
- What's this kind of syntax in PHP?
- How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?
- PHP != and == operators
- The 3 different equals
- Type-juggling and (strict) greater/lesser-than comparisons in PHP
- What does "===" mean?
- How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?
- The 3 different equals
- Type-juggling and (strict) greater/lesser-than comparisons in PHP
- PHP != and == operators
- Is there a difference between !== and != in PHP?
- comparing, !== versus !=
- What is the difference between <> and !=
- PHP operator <>
- PHP's <> operator
- What is the difference between <> and !=
- Type-juggling and (strict) greater/lesser-than comparisons in PHP
<=>
Comparison Operators (since PHP 7.0)
- What is the difference between the | and || operators?
- What Does Using A Single Pipe '|' In A Function Argument Do?
- What is the difference between the | and || operators?
- PHP - and / or keywords
- What exactly does || mean?
- The behaviour of the or operator in PHP
+
Arithmetic Operators, Array Operators
+=
and -=
Assignment Operators
++
and --
Incrementing/Decrementing Operators
- Difference between period and comma when concatenating with echo versus return?
- What does a . (dot) do in PHP?
- What does $$ (dollar dollar or double dollar) mean in PHP?
- what is "$$" in PHP
- $function() and $$variable
<?=
Short Open Tags
[]
Arrays (short syntax since PHP 5.4)
- PHP arrays... What is/are the meaning(s) of an empty bracket?
- What is the meaning of []
- Php array_push() vs myArray[]
- What does [] mean when reading from a PHP array?
- Shorthand for arrays: literal
$var = []
empty array
...
Argument unpacking (since PHP 5.6)
**
Exponentiation (since PHP 5.6)
#
One-line shell-style comment
?->
NullSafe Operator Calls (since PHP 8.0)
Incrementing / Decrementing Operators
++
increment operator
--
decrement operator
Example Name Effect
---------------------------------------------------------------------
++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one.
--$a Pre-decrement Decrements $a by one, then returns $a.
$a-- Post-decrement Returns $a, then decrements $a by one.
These can go before or after the variable.
If put before the variable, the increment/decrement operation is done to the variable first then the result is returned. If put after the variable, the variable is first returned, then the increment/decrement operation is done.
For example:
$apples = 10;
for ($i = 0; $i < 10; ++$i) {
echo 'I have ' . $apples-- . " apples. I just ate one.\n";
}
In the case above ++$i
is used, since it is faster. $i++
would have the same results.
Pre-increment is a little bit faster because it really increments the variable and after that 'returns' the result. Post-increment creates a special variable, copies there the value of the first variable and only after the first variable is used, replaces its value with second's.
However, you must use $apples--
, since first, you want to display the current number of apples, and then you want to subtract one from it.
You can also increment letters in PHP:
$i = "a";
while ($i < "c") {
echo $i++;
}
Once z
is reached aa
is next, and so on.
Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.
Stack Overflow Posts:
这篇关于参考——这个符号在 PHP 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!