I have just asked a question on SO and found out I can make use of ++
to increment letters. I have now tried this:
$last_id = get_last_id();
echo gettype($last_id); //string
echo 'L_ID ->'.$last_id.'<br />'; //AAF
$next_id = $last_id++;
echo 'N_ID ->'.$next_id.'<br />';//AAF
The following example which I was given works fine:
$x = 'AAZ';
$x++;
echo $x;//ABA
What is going on? Must be the end of the work day...
Thanks all for any help
++ is a post increment operator, thus
$next_id = $last_id++;
assigns the current value of $last_id to $next_id, and then increments it. What you want is a pre-increment
$next_id = ++$last_id;
Putting ++
after a variable will increment it when the statement it's part of completes. You're assigning to $next_id
the value of $last_id
before it's incremented. Instead, use ++$last_id
, which increments before the value of the variable is used.