Generate incremental number identifier, upper and lower case letters

How can I generate incremental id in php, lowercase and uppercase mix numbers?

For example, I tried:

$hello = "aaa0"; for ($i=0; $i < 10000; $i++) { echo $hello++; echo "<br>"; } 

Then it returns:

 aaa0 aaa1 aaa2 ... aaa9 aab0 aab1 

I would like to generate strings like:

 aaa0 aaa1 aaa2 ... aaaa aaab aaac ... aaaz aaaA 

The first numbers are from 0 to 9, then the characters from a to z, then the characters from A to Z. Each positional char must go in this range.

How can i do this?

EDIT: I want every character in the string to vary within this range. I want to go from 0 to 9, then from a to z, then from A to Z. When it ends, char go to 0 and char go to the left step in one. For instance:

 0000 0001 0002 ... 0009 000a 000b ... 000y 000z 000A 000B ... 000X 000Z 0010 0011 0012 .... 0019 001a 
+6
source share
2 answers

Using 0.1-9, az and AZ are "base 62". Converting from base 10 to base 62 is very easy in PHP.

 <?php echo base_convert(10123, 10,26), "\n"; // outputs: 'ep9' echo base_convert('ep9', 26, 10), "\n"; // output 10123 
+2
source

This should work for you:

 <?php $hello = "aaa"; //'aaa0' -> 'aaa9' for ($count = 0; $count <= 9; $count++) echo $hello . $count . "<br />"; //'aaaa' -> 'aaaz' foreach (range('a', 'z') as $char) echo $hello . $char . "<br />"; //'aaaA' -> 'aaaZ' foreach (range('A', 'Z') as $char) echo $hello . $char . "<br />"; ?> 

EDIT:

This only works with 3 digits. After you have exhausted your memory for sure.

 <?php $array = array(); $maxLength = 3; $output = array(); ini_set('memory_limit', '-1'); $time_start = microtime(true); foreach(range(0, 9) as $number) $array[] = $number; foreach(range('a', 'z') as $char) $array[] = $char; foreach(range('A', 'Z') as $char) $array[] = $char; function everyCombination($array, $arrLength, $size, $perArr = array(), $pos = 0, &$found = array()) { if ($size == $pos) { $found[] = vsprintf("%s%s%s", $perArr); return; } for ($count = 0; $count < $arrLength; $count++) { $perArr[$pos] = $array[$count]; everyCombination($array, $arrLength, $size, $perArr, $pos+1, $found); } return $found; } $output = everyCombination($array, count($array), $maxLength); for($count = 0; $count < count($output); $count++) echo $output[$count] . "<br/>"; echo "DONE!"; $time_end = microtime(true); $time = $time_end - $time_start; echo round($time,2) . " s"; ?> 
+5
source

Source: https://habr.com/ru/post/979699/


All Articles