I am trying to loop through letters rather than numbers.
I am trying to do this using chr and the number equivalent but it doesn't seem to be happening!
I want four letter loop.
So AAAA, AAAB, AAAC etc through to ZZZZ - and yes I know this will likely take a while to execute!
To loop through words in a string in PHP, use explode() function with space as delimiter. The explode() functions returns an array containing words and you can then use a looping statement to traverse through the words one by one.
PHP has str_split () function, which is used to print every character of a string. No need to use any loop.
Often when you write code, you want the same block of code to run over and over again a certain number of times. So, instead of adding several almost equal code-lines in a script, we can use loops. Loops are used to execute the same block of code again and again, as long as a certain condition is true.
How many main parameter are used in for loop? Explanation: There are three main parameters to the code, namely the initialization, the test condition and the counter.
Why don't you make an array of letters and then use nested loops:
$letters = range('A', 'Z'); foreach ($letters as $one) { foreach ($letters as $two) { foreach ($letters as $three) { foreach ($letters as $four) { echo "$one$two$three$four"; } } } }
for( $x = "AAAA"; ; $x++) { echo $x."\n"; if( $x == "ZZZZ") break; }
Incrementing a letter will cycle it through the alphabet similar to the column names in Excel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With