Mjukis Mjukis - 2 years ago 129
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download