Write a PHP program to create a letter range with arbitrary length
<?php function letter_range($length) { $data_range = array(); $letters = range('A', 'Z'); for($i=0; $i<$length; $i++) { $position = $i*26; foreach($letters as $ii => $letter) { $position++; if($position <= $length) $data_range[] = ($position > 26 ? $data_range[$i-1] : '').$letter; } } return $data_range; } print_r(letter_range(7)); ?>
Sample Output:
Array ( [0] => A [1] => B [2] => C [3] => D [4] => E [5] => F [6] => G )
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
Array ( [0] => A [1] => B [2] => C [3] => D [4] => E [5] => F [6] => G )need an explanation for this answer? contact us directly to get an explanation for this answer