i need to do a simple loop in php to get char from a to z.. something like:
for($i=0;$i<aNumber;$i++) echo "char = ".intToChar($i)."<br>"; where aNumber is less then 20
You can create an array of characters easily with range [docs]:
$chars = range('a', 'z'); Or if you really only want to print them:
echo implode('<br />', range('a', 'z')); You need understand ASCII table. See in this link. Codes for A - Z is 65 - 90 and a - z is 97 - 122.
for($i = 97; $i <= 122; $i++) echo chr($i); I SOLVED IN THIS WAY:
$i = 0; $char = 'a'; $aNumber = xx; while($i<$aNumber){ echo $char."<br>"; $char++; $i++; } To return character specified by ASCII code/number use chr function. Since you want to loop from 0 to 20, then you need to add 97 to $i, 97 is ASCII code for letter a:
for($i=0;$i<$aNumber;$i++) echo "char = ".chr($i+97)."<br>"; // + 97 because it is ASCII 'a' If you just want to loop through those letters you can do it like this:
for($i = ord('a'); $i < ord('z'); $i++) echo "char = ".chr($i)."<br>"; Additionally if you just want to get array of those characters you can use range function:
$chars = range('a', 'z');