Decrement character with php

前端 未结 5 945
盖世英雄少女心
盖世英雄少女心 2021-01-12 01:15

Why is it that it\'s ok to increment character but not decrement with PHP?

PHP



        
5条回答
  •  -上瘾入骨i
    2021-01-12 01:21

    As chris85 mentioned: "Character variables can be incremented but not decremented"


    PHP supports C-style pre- and post-increment and decrement operators.

    Incrementing/Decrementing Operators

    1. ++$a Pre-increment Increments $a by one, then returns $a.
    2. $a++ Post-increment Returns $a, then increments $a by one.
    3. --$a Pre-decrement Decrements $a by one, then returns $a.
    4. $a-- Post-decrement Returns $a, then decrements $a by one.

    Note: The increment/decrement operators only affect numbers and strings. Arrays, objects and resources are not affected. Decrementing NULL values has no effect too, but incrementing them results in 1.


    SRC: http://php.net/manual/en/language.operators.increment.php

提交回复
热议问题