I need to loop through an array of data and print an ‘incrementing’ letter for each array value. I know I can do this:
$array = array(11, 33, 44, 98, 1, 3, 2, 9, 66, 21, 45); // array to loop through
$letters = array('a', 'b', 'c', ...); // array of letters to access
$i = 0;
foreach($array as $value) {
echo $letters[$i++] . " - $value";
}
It seems that there should be a better way than having to create an alphabet array. Any suggestions?
Note – My loop will never get through the entire alphabet, so I’m not concerned about running out of letters.
1 Answer