Reputation: 77
What I am doing is taking a vehicle VIN number and taking the last 6 digits of it and storing it as a stock number. The issue I have is I have a function that goes and checks the database to make sure that stock number exists. If it does (can have the same vehicle in inventory again from buy back, etc) I want to concat at the end of the sting A through Z.
if(strlen($vin) > 9) {
$stocknum = substr($vin,-6);
while(verfiyUnique($mysqli, $stocknum) != true) {
if(strlen($stocknum < 7)) {
$stocknum = substr($vin,-6) . "A";
}else{
?
}
}
return $stocknum;
How do I increment lets say A to B or B to C if it does match?
Thanks in advance for your help!
Upvotes: 0
Views: 49
Reputation: 2278
You could also use $letters = range('A','Z')
to create an array of uppercase letters and then increment an index variable to access the array. E.g.: $letters[$i]
would output A
Upvotes: 1
Reputation: 2278
You could increment the ascii number and use the chr()
function to convert it to the relevant character. E.g.: chr(65)
would output A
See http://php.net/manual/en/function.chr.php for more info as well as a link to an ASCII table.
Upvotes: 1