I’m having trouble with decreasing a string ID. This is the case:
// given $row[0]['orderid'] = "ORD00389" (varchar)
$nextID = $row[0]['orderid'];
$prevID = $row[0]['orderid'];
$nextID++; // echo 'ORD00390'
$prevID--; // echo 'ORD00388'
What I learned so far is this lovely paragraph:
PHP follows Perl’s convention when dealing with arithmetic operations
on character variables and not C’s. For example, in PHP and Perl $a =
‘Z’; $a++; turns $a into ‘AA’, while in C a = ‘Z’; a++; turns a into
‘[‘ (ASCII value of ‘Z’ is 90, ASCII value of ‘[‘ is 91). Note that
character variables can be incremented but not decremented and even so
only plain ASCII characters (a-z and A-Z) are supported.
Incrementing/decrementing other character variables has no effect, the
original string is unchanged.
Is there any efficient way (built-in function) to decrease that string in PHP?
If it ends in ORD every time you can get rid of the ORD, subtract 1, then put it back together.
If it doesn’t begin with ORD every time you could replace all non digits