PHP 8.5.0 Alpha 1 available for testing

Voting

: min(seven, three)?
(Example: nine)

The Note You're Voting On

lsblsb at gmx dot de
11 years ago
I needed a function, that creates a letter range with arbitrary length.
You specify via the $length parameter, how many entries you need.
Logic is analog to the logic of the column-titles in a calc-sheet.

<?php

/**
* create a letter range with arbitrary length
* @param int $length
* @return array
*/
function createLetterRange($length)
{
$range = array();
$letters = range('A', 'Z');
for(
$i=0; $i<$length; $i++)
{
$position = $i*26;
foreach(
$letters as $ii => $letter)
{
$position++;
if(
$position <= $length)
$range[] = ($position > 26 ? $range[$i-1] : '').$letter;
}
}
return
$range;
}
?>

<< Back to user notes page

To Top