北城已荒凉 2010-09-17 16:24 采纳率: 0%
浏览 481
已采纳

Reference ー在 PHP 中这个符号表示什么?

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)


: 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


转载于:https://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php

  • 写回答

17条回答 默认 最新

  • 旧行李 2010-09-17 16:30
    关注

    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:

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(16条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?