PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $end = 'ae'; // The list of all possible characters in the alphabet $alphabet = range('a', 'z'); // Flip this array so that the letter becomes the key and the value is index (0 based) $alphabetSearch = array_flip($alphabet); $result = 0; $endLen = strlen($end); // Use the target string as an array an iterate over each char for ($i = 0; $i < $endLen; $i++) { // Multiply the result by the number of chars in the alphaber to maintain the scale of each char $result *= count($alphabet); // Add on the index of the new char (+1 as it's 0 based) $result += ($alphabetSearch[$end[$i]] ?? 0) + 1; } echo $result;
Show:  
Copy Clear