473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Looping The Alphabet and Numbers

Hey,

I want to create a list of letters, starting at AA1 to ZZ15.

IE,

AA1, AA2, AA3, AA4, AA5, AA6, AA7, AA8, AA9, AA10, AA11, AA12, AA13, AA14, AA15, AB1, AB2 etc etc.

I am familiar with loop processes but can't get my head around the logic to this one.

Help appreciated. Thanks.
Mar 2 '08 #1
6 2722
hsriat
1,654 Expert 1GB
[php]<?php
$abc = array ("A","B","C","D","E",.../*upto*/.....,"X","Y","Z");
$output = array();
for ($i=0; $i<26; $i++)
{
for ($j=0; $j<26; $j++)
{
for ($k=1; $k<=15; $k++)
{
array_push($output, $abc[$i].$abc[$j].$k);
}
}
}
?>[/php]

See if the $output array give you the right thing.
Mar 2 '08 #2
dlite922
1,584 Expert 1GB
[PHP]
<?php
$number = 15;
$result = array();
$alpha = array('A','B','C','D','E','F','G','H','I','J','K', 'L','M','N','O','P','Q','R','S','T','U','V','W','X ','Y','Z');
for ($first = 0; $first < count($alpha); $first++) {
for ($second = 0; $second < count($alpha); $second++) {
for ($k = 1; $k <= $number; $k++) {
array_push($result,$alpha[$first].$alpha[$second].$k);
}
}
}
print_r($result); // here's the result, do what you want with it. 10139 Results!!!
?>

[/PHP]

let me know if any questions.
Mar 2 '08 #3
dlite922
1,584 Expert 1GB
damn. you beat me to it!

:P mines better!!

/joke, its almost exactly the same.

then again, i don't know how else you can do this.
Mar 2 '08 #4
hsriat
1,654 Expert 1GB
damn. you beat me to it!

:P mines better!!

/joke, its almost exactly the same.

then again, i don't know how else you can do this.
Out of two code doing the same thing, the one having less number of lines is better. Going to the depth, you will find mine will consume less memory and machine cycles. :p
(j/k)

But this used to be thought many years ago, when memory and CPU speed were limited. Now, no one cares!, neither its required to care, unless its Embedded C or J2ME.

:)

Harpreet
Mar 2 '08 #5
dlite922
1,584 Expert 1GB
Out of two code doing the same thing, the one having less number of lines is better. Going to the depth, you will find mine will consume less memory and machine cycles. :p
(j/k)

But this used to be thought many years ago, when memory and CPU speed were limited. Now, no one cares!, neither its required to care, unless its Embedded C or J2ME.

:)

Harpreet
good point! but I have a better one.

(Sorry for being so competitive, its 1:00 AM and i'm bored)

Better was in the definition that it was easier for him to understand, and even more importantly that a code should be extensible.

As you can see in yours if i choose to drop out letters, the 25 is hardcoded as well as the 15 where in mine you can change those values in their declaration and my code does not have to be changed.

PS: Also i'm trying to knock "dafodil" off the board ;) ....sshhh!! don't tell him I said that.
Mar 2 '08 #6
hsriat
1,654 Expert 1GB
I hard coded it to 26 (later edited form 25), coz there are 26 English alphabets. :D

Ok, your is better. Happy now?

(It's 1:00 PM here and I have many other things to do) :p

Regards,
Harpreet :)
Mar 2 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
5
by: skinnybloke | last post by:
Hi I am trying to do something with PHP and having problems - a bit of a a PHP novice I'm afraid. What I am trying to achieve is to display the alphabet and numbers 0-9 on a web page. I want...
5
by: Bruce Lawrence | last post by:
I'm running Access 97 and my modules are looping if someone puts an invalid value in. The setup: 3 macros - get_clock_num, verify_clocknum, append_to_history 3 functions. each in their own...
5
by: Stefan Krah | last post by:
Hello, I am currently writing code where it is convenient to convert char to int . The conversion function relies on a character set with contiguous alphabets. int set_mesg(Key *key, char...
8
by: Jack Addington | last post by:
I want to scroll through the alphabet in order to scroll some data to the closest name that starts with a letter. If the user hits the H button then it should scroll to the letter closest to H. ...
0
by: rockdale | last post by:
Hi, all: I implemented an alphabet list so that when user click letter A then I will re-bind a gridview control using SQL stored procedure. It works fine. The problem is I populate my alphabet...
1
by: mktilu | last post by:
do we have any function to convert the numbers into alphabet in vb 6.For example 25 to be converted to twenty Five. Its urgent
20
by: Ifoel | last post by:
Hi all, Sorry im beginer in vb. I want making programm looping character or number. Just say i have numbers from 100 to 10000. just sample: Private Sub Timer1_Timer() if check1.value= 1...
20
by: geebanga88 | last post by:
HI i have a method that is supose to store the alphabet in an array however dont think that it is being added to the array. public static void GetAlphabet (char alphabet) { int...
4
by: kundasang | last post by:
Hello, how to do simple code for: if(alphabet) output ERROR because char is int I cannot do like this: if(sale >= 'a' && sale =< 'z')
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.