Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

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

What is this? (这是什么?)

This is a collection of questions that come up every now and then about syntax in PHP.

(这是有关PHP语法的不时出现的问题的集合。)

This is also a Community Wiki, so everyone is invited to participate in maintaining this list.

(这也是一个社区Wiki,因此邀请所有人参与维护此列表。)

Why is this? (为什么是这样?)

It used to be hard to find questions about operators and other syntax tokens.1

(过去很难找到有关运算符和其他语法标记的问题。1)
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.

(主要思想是链接到Stack Overflow上的现有问题,因此我们更容易引用它们,而不必复制PHP手册中的内容。)

Note: Since January 2013, Stack Overflow does support special characters .

(注意:自2013年1月起,Stack Overflow 确实支持特殊字符 。)

Just surround the search terms by quotes, eg [php] "==" vs "==="

(只需用引号将搜索词引起来,例如[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.

(PHP手册的链接页面以及链接的问题可能会回答您的问题。)

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

(&& <a href="https://stackoom.com/link/aHR0cDovL3NlY3VyZS5waHAubmV0L21hbnVhbC9lbi9sYW5ndWFnZS5vcGVyYX


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Live example

(现场例子)

In the case above ++$i is used, since it is faster.

(在上面的情况下使用++$i ,因为它速度更快。)

$i++ would have the same results.

($i++将具有相同的结果。)

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.

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

You can also increment letters in PHP:

(您还可以在PHP中递增字母:)

$i = "a";
while ($i < "c") {
    echo $i++;
}

Once z is reached aa is next, and so on.

(一旦到达z则下一个是aa ,依此类推。)

Note that character variables can be incremented but not decremented and even so only plain ASCII characters (az and AZ) are supported.

(请注意,字符变量可以递增但不能递减,即使如此,仅支持纯ASCII字符(az和AZ)。)


Stack Overflow Posts:

(堆栈溢出帖子:)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...