Recently I needed to increment letters in PHP within a loop repetition.
For each iteration, instead of numerical indices, it needed letters of the alphabet.
So, as I already know that PHP does incremental letters (and to be very simple), I did something like that.
for($letra = 'a'; $letra != 'aa'; $letra++) {
echo $letra;
}
// abcdefghijklmnopqrstuvwxyz
However, because I have never seen this documented and in any other language I know of such functionality, I was in doubt whether to use it or not.
Because of coding (and so on), is it safe to use this feature, or is it better to appeal to friends chr
or range('a', 'z')
, as in the example below?
for($letra = 97; $letra <= 122; $letra++) {
echo chr($letra);
}
//abcdefghijklmnopqrstuvwxyz
echo implode('', range('a', 'z')); //abcdefghijklmnopqrstuvwxyz
//abcdefghijklmnopqrstuvwxyz