参考-这个符号在PHP中是什么意思? [英] Reference — What does this symbol mean in PHP?

查看:100
本文介绍了参考-这个符号在PHP中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是什么?

这是有关PHP语法的不时出现的问题的集合.这也是一个社区Wiki,因此邀请所有人参与维护此列表.

这是为什么?

过去很难找到有关运算符和其他语法标记的问题.¹
主要思想是链接到Stack Overflow上的现有问题,因此我们更容易引用它们,而不必复制PHP手册中的内容.

注意:自2013年1月起,堆栈溢出不支持特殊字符.只需用引号将搜索字词括起来,例如 [php] "==" vs "==="

我应该在这里做什么?

如果有人因为提出这样的问题而将您指向此处,请在下面找到特定的语法. PHP手册的链接页面以及链接的问题可能会回答您的问题.如果是这样,建议您增加答案.此列表不能替代其他人提供的帮助.

列表

如果您的特定令牌未在下面列出,则可以在解析器列表中找到令牌.


& 按位运算符参考


=& 参考


&= 按位运算符


&& 逻辑运算符


% 算术运算符


!! 逻辑运算符


@ 错误控制运算符


?: 三元运算符


?? 空联合运算符(自PHP 7起)


?string ?int ?array ?bool ?float 可返回值的类型声明(自PHP 7.1起)


: 控制结构的替代语法三元运算符


:: 范围解析运算符


\ 命名空间


-> 类和对象


=> 数组


^ 按位运算符


>> 按位运算符


<< 按位运算符


<<< Heredoc或Nowdoc


= 分配运算符


== 比较运算符


=== 比较运算符


!== 比较运算符


!= 比较运算符


<> 比较运算符


<=> 比较运算符(自PHP 7.0起)


| 按位运算符


|| 逻辑运算符


~ 按位运算符


+ 算术运算符数组运算符


+=-= 分配运算符


++-- 递增/递减运算符


.= 分配运算符


. 字符串运算符


, 函数参数

, 变量声明


$$ 变量


` 执行运算符


<?= 打开标签


[] 数组(PHP 5.4以来的短语法) )


<? 打开和关闭标签


... 参数解压缩(自PHP 5.6起)


** 幂运算(自PHP 5.6起)


# 单行外壳样式注释


:? 可为空的返回类型


解决方案

递增/递减运算符

++增量运算符

--减法运算符

 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.
 

这些变量可以在变量之前或之后.

如果放在变量之前,先对变量进行递增/递减操作,然后返回结果.如果将变量放在变量之后,则首先返回该变量,然后执行递增/递减操作.

例如:

$apples = 10;
for ($i = 0; $i < 10; ++$i) {
    echo 'I have ' . $apples-- . " apples. I just ate one.\n";
}

实时示例

在使用++$i的情况下,因为它更快. $i++将具有相同的结果.

预增量要快一点,因为它确实增加了变量,然后返回"结果.后增量创建一个特殊变量,在其中复制第一个变量的值,只有在使用第一个变量后,才将其值替换为第二个.

但是,必须使用$apples--,因为首先要显示当前的苹果数,然后然后要减去一个苹果.

您还可以在PHP中增加字母:

$i = "a";
while ($i < "c") {
    echo $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 to 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


=& References


&= Bitwise Operators


&& Logical Operators


% Arithmetic Operators


!! Logical Operators


@ Error Control Operators


?: Ternary 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


:: Scope Resolution Operator


\ Namespaces


-> Classes And Objects


=> Arrays


^ Bitwise Operators


>> Bitwise Operators


<< Bitwise Operators


<<< Heredoc or Nowdoc


= Assignment Operators


== Comparison Operators


=== Comparison Operators


!== Comparison Operators


!= Comparison Operators


<> Comparison Operators


<=> Comparison Operators (since PHP 7.0)


| Bitwise Operators


|| Logical Operators


~ Bitwise Operators


+ Arithmetic Operators, Array Operators


+= and -= Assignment Operators


++ and -- Incrementing/Decrementing Operators


.= Assignment Operators


. String Operators


, Function Arguments

, Variable Declarations


$$ Variable Variables


` Execution Operator


<?= Short Open Tags


[] Arrays (short syntax since PHP 5.4)


<? Opening and Closing tags


... Argument unpacking (since PHP 5.6)


** Exponentiation (since PHP 5.6)


# One-line shell-style comment


:? Nullable return types


解决方案

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";
}

Live example

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆