找回密码
 立即注册
PHPdoesmeanoperator | 软件设计/软件工程 2022-05-03 246 0star收藏 版权: . 保留作者信息 . 禁止商业使用 . 禁止修改作品
问题
这是一组不时弹出的关于 PHP 语法的问题。这也是一个社区 wiki,因此邀请所有人参与维护此列表。

过去很难找到有关运算符和其他语法标记的问题。 1

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

注意:自 2013 年 1 月以来,Stack Overflow 确实支持特殊字符。只需将搜索词括在引号中,例如[php]“==” vs“===”

如果有人因为您提出这样的问题而指向您,请在下面找到确切的语法。 PHP 手册页面的链接和链接的问题可能会回答您的问题。如果是这样,我们鼓励您投票赞成答案。此列表不能替代其他人提供的帮助。

如果您的特定标签未在下面列出,您可以在解析器标签列表中找到它。
  1. Bitwise Operators or ReferencesWhat does it mean to start a PHP function with an ampersand?Understanding PHP & (ampersand, bitwise and) operatorPHP "&" operatorDifference between & and && in PHPWhat 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? (&$)=&ReferencesReference assignment operator in PHP, =&What do the "=&" and "&=" operators in PHP mean?What do the '&=' and '=&' operators do?What does =& mean in PHP?&=Bitwise OperatorsWhat do the "=&" and "&=" operators in PHP mean?What do the '&=' and '=&' operators do?&&Logical Operators'AND' vs '&&' as operatorDifference between & and && in PHPIs there any difference between "and" and "&&" operators in PHP?PHP - and / or keywords%Arithmetic OperatorsWhat does the percent sign mean in PHP?What is the PHP operator % and how do I use it in real-world examples?!!Logical OperatorsDouble not (!!) operator in PHP@Error Control OperatorsWhat is the use of the @ symbol in PHP?'At' symbol before variable name in PHP: @$_POSTPHP functions and @functionsShould I use @ in my PHP code?What does @ mean in PHP??:Ternary OperatorWhat are the PHP operators "?" and ":" called and what do they do??: operator (the 'Elvis operator') in PHPWhere can I read about conditionals done with "?" and ":" (colon)?Using PHP 5.3 ?: operator??Null Coalesce Operator (since PHP 7)C#'s null coalescing operator (??) in PHP?string?int?array?bool?floatNullable return type declaration (since PHP 7.1)Nullable return type declaration:Alternative syntax for control structures, Ternary OperatorWhat is ":" in PHP?What does ":" mean in PHP?::Scope Resolution OperatorWhat 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\NamespacesBackslash in PHP -- what does it mean?What does a \ (backslash) do in PHP (5.3+)?->Classes And ObjectsWhat is the "->" PHP operator called and how do you say it when reading code out loud?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?=>ArraysWhat does "=>" mean in PHP?Use of => in PHPWhat does $k => $v in foreach($ex as $k=>$v) mean?^Bitwise OperatorsHow does the bitwise operator XOR ('^') work?What does ^ mean in PHP?>>Bitwise OperatorsWhat does >> mean in PHP?<<Bitwise OperatorsStrange print behaviour in PHP?<<<Heredoc or NowdocWhat does <<<END mean in PHP?PHP expression <<<EOBIn PHP, what does "<<<" represent?Using <<<CON in PHPWhat's this kind of syntax in PHP?=Assignment OperatorsThe 3 different equals==Comparison OperatorsHow do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?PHP != and == operatorsThe 3 different equalsType-juggling and (strict) greater/lesser-than comparisons in PHP===Comparison OperatorsWhat does "===" mean?How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?The 3 different equalsType-juggling and (strict) greater/lesser-than comparisons in PHP!==Comparison OperatorsWhat does !== comparison operator in PHP mean?Is there a difference between !== and != in PHP?!=Comparison OperatorsPHP != and == operatorsIs there a difference between !== and != in PHP?comparing, !== versus !=What is the difference between <> and !=<>Comparison OperatorsPHP operator <>PHP's <> operatorWhat is the difference between <> and !=Type-juggling and (strict) greater/lesser-than comparisons in PHP<=>Comparison Operators (since PHP 7.0)Spaceship (three way comparison) operator|Bitwise OperatorsWhat is the difference between the | and || operators?What Does Using A Single Pipe '|' In A Function Argument Do?||Logical OperatorsWhat is the difference between the | and || operators?PHP - and / or keywordsWhat exactly does || mean?The behaviour of the or operator in PHP~Bitwise OperatorsWhat does this ~ operator mean here?+Arithmetic Operators, Array Operators+ operator for array in PHP?+= and -=Assignment OperatorsWhat is += used for?What does `$page -= 1` in my PHP document mean?++ and --Incrementing/Decrementing OperatorsUnderstanding IncrementingAnswer below.=Assignment OperatorsWhat is the difference between .= and += in PHP?To understand a line of PHP.String OperatorsDifference between period and comma when concatenating with echo versus return?What does a . (dot) do in PHP?,Function ArgumentsDifference between period and comma when concatenating with echo versus return?,Variable DeclarationsWhat do commas mean in a variable declaration?$$Variable VariablesWhat does $$ (dollar dollar or double dollar) mean in PHP?what is "$$" in PHP$function() and $$variable`Execution OperatorWhat are the backticks `` called?<?=Short Open TagsWhat does this symbol mean in PHP <?=What does '<?=' mean in PHP?What does <?= mean?[]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<?Opening and Closing tagsAre PHP short tags acceptable to use?...Argument unpacking (since PHP 5.6)**Exponentiation (since PHP 5.6)#One-line shell-style commentCan I use hashes for comments in PHP?:?Nullable return typesphp method argument type hinting with question mark (?type)
复制代码

回答
递增/递减运算符

++ 增量运算符

-- 递减运算符
  1. Example    Name              Effect
  2. ---------------------------------------------------------------------
  3. ++$a       Pre-increment     Increments $a by one, then returns $a.
  4. $a++       Post-increment    Returns $a, then increments $a by one.
  5. --$a       Pre-decrement     Decrements $a by one, then returns $a.
  6. $a--       Post-decrement    Returns $a, then decrements $a by one.
复制代码

它们可以在变量之前或之后。

如果前面有变量,则先对变量进行递增/递减,然后返回结果。如果放在变量之后,则首先返回变量,然后是递增/递减操作。

例如:
  1. $apples = 10;
  2. for ($i = 0; $i < 10; ++$i) {
  3.     echo 'I have ' . $apples-- . " apples. I just ate one.\n";
  4. }
复制代码

例子

在上述情况下,使用 ++$i 因为它更快。 $i++ 将给出相同的结果。

Pre increment 稍微快一些,因为它确实增加了变量然后返回结果。后增量创建一个特殊变量,其中第一个变量的值被复制,并且只有在第一个变量被使用后,它的值才被第二个变量替换。

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

也可以在 PHP 中增加字母:
  1. $i = "a";
  2. while ($i < "c") {
  3.     echo $i++;
  4. }
复制代码

一旦你到达 z ,下一个是 aa ,依此类推。

堆栈溢出帖子:了解增量





上一篇:JavaScript 中的乘法表
下一篇:如何在javascript中的对象数组中获取相同的对象