Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong><a href="http://php.net/manual/en/language.operators.increment.php" rel="noreferrer">Incrementing / Decrementing Operators</a></strong></p> <p><code>++</code> increment operator</p> <p><code>--</code> decrement operator</p> <pre class="lang-none prettyprint-override"><code>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. </code></pre> <p>These can go before or after the variable.</p> <p>If put before the variable, the increment/decrement operation is done to the variable <strong>first</strong> then the result is returned. If put after the variable, the variable is <strong>first</strong> returned, then the increment/decrement operation is done.</p> <p>For example:</p> <pre><code>$apples = 10; for ($i = 0; $i &lt; 10; ++$i) { echo 'I have ' . $apples-- . " apples. I just ate one.\n"; } </code></pre> <p><strong><a href="http://codepad.org/5ZD3j0xb" rel="noreferrer">Live example</a></strong></p> <p>In the case above <code>++$i</code> is used, since it is faster. <code>$i++</code> would have the same results.</p> <p>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.</p> <p>However, you must use <code>$apples--</code>, since first you want to display the current number of apples, and <strong>then</strong> you want to subtract one from it.</p> <p>You can also increment letters in PHP:</p> <pre><code>$i = "a"; while ($i &lt; "c") { echo $i++; } </code></pre> <p>Once <code>z</code> is reached <code>aa</code> is next, and so on.</p> <blockquote> <p>Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.</p> </blockquote> <hr> <p><strong>Stack Overflow Posts:</strong></p> <ul> <li><strong><a href="https://stackoverflow.com/questions/1968371/understanding-incrementing">Understanding Incrementing</a></strong> </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload