Tell me an algorithm that could convert a string to a number.
A = 1 B = 2 c = 3 ... Z = 26 AA = 27 AB = 28 AC = 29 ...
ABA =?
I write something like this without checking the code, so it can with errors:
$letters = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $letters = array_flip($letters); $variant = 'ABA'; $newVariant = str_split($variant); $sum = 0; foreach($newVariant as $items){ $sum *= 26; $sum+= ($letters[$items]+1); } echo $sum;
Checked and corrected
Source: https://ru.stackoverflow.com/questions/232755/
All Articles