Need a PHP function to generate a range() A to ZZZZ

I'm having trouble creating a PHP function that will output every possible letter combination, for example

a
b
c
......... etc
......... etc
........ then
aa
ab
ac
ad
......... etc
......... etc
........ then
aaa
aab
aac
......... etc
......... etc
........ then
zzx
zzy
zzz


I need the function to accept a $depth value, for example a depth of 3 would end at ZZZ.

I know the PHP range function is useful range('a','z');
but this only creates an array with A-Z

Could anyone help me with this. Thanks in advance

TotallyMeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ycTINCommented:

<?php
$r = mkRange('A','ZZ');
echo count($r);
 
function mkRange($start,$end) {
	$count = strToInt($end) - strToInt($start);
	$r = array();
	do {$r[] = $start++;} while ($count--);
	return $r;
}
 
function strToInt($str) {
	$str = strrev($str);
	$dec = 0;
	for ($i = 0; $i < strlen($str); $i++) {
		$dec += (base_convert($str[$i],36,10)-9) * pow(26,$i);
	}
	return $dec;
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TotallyMeAuthor Commented:
Worked great, thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.