<?php
$s = "pa99";
$s++;
echo $s;
?>
The above code outputs to “pb00”
What i wanted was “pa100” and so on.
But also in case its “pa”, I want it to go to “pb” which works well with
increment operator.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You are, as Michael says, trying to increment a string – it Does Not Work That Way ™. What you want to do is this:
There’s no automated way to increment a string (aa, ab, etc) the way you’re asking. You could turn each letter into a number between 1-26 and increment them, and then increment the previous one on overflow. That’s kind of messy, though.
To separate the integer from the string, try this:
PHP split string into integer element and string