Mjukis Mjukis - 10 months ago 63
PHP Question

Decrement character with php

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


$a = "a";
echo $a. "<br>"; //a
echo ++$a. "<br>"; //b
echo --$a. "<br>"; //b

Is there a simple way as
to decrement a charrater?


There is no direct way to decrement alphabets. But with a simple function you can achieve it:

function decrementLetter($Alphabet) {
    return chr(ord($Alphabet) - 1);

Source, thanks to Ryan O'Hara