Untitled UI logotext
Solutions
WebsitesEcommerceMobile AppsWeb AppsProduction Support & Maintenance
Our work
Company
About usBlogPodcastContact us
Book a free consultation

How Can I Make a Php Alphabet Loop?

Olivia Rhye

A useful feature of many coding languages is the "for loop". A basic loop in php has for following structure:

for (init; condition; increment)
{
code to be executed;
}

Parameters:

init: Mostly used to set a counter (but can be any code to be executed once at the beginning of the loop)
condition: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, loop ends.
increment: Mostly used to increment a counter (but can be any code to be executed at the end of the iteration)

So basically, all I used this for was to go over a set of numbers, with i=0, and i++ everytime if went through the loop until i was less than 'x'. I didn't realize php can also loop over the alphabet (using foreach).

foreach(range('a','z') as $i) {
echo $i;
}

Knowledge shared.

Ready to start a project?

Book a free consultation
Untitled UI logotext
Our work
About us
Blog
Careers
Submit a ticket
Agency Partnerships
Contact
© 2024 fjorge. All rights reserved.
Privacy