PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How can I loop through the members of an array?


If you want to create a quick and easy loop to show the values of an array, then all you need is the trusty foreach control structure, thus:

<?php
$alphabet 
range("A","Z");
foreach(
$alphabet as $letter) { echo "Ooh look!  The letter $letter\n"; }
?>


Prints this:

Ooh look! The letter A
Ooh look! The letter B
Ooh look! The letter C
Ooh look! The letter D
Ooh look! The letter E
Ooh look! The letter F
Ooh look! The letter G
Ooh look! The letter H
Ooh look! The letter I
Ooh look! The letter J
Ooh look! The letter K
Ooh look! The letter L
Ooh look! The letter M
Ooh look! The letter N
Ooh look! The letter O
Ooh look! The letter P
Ooh look! The letter Q
Ooh look! The letter R
Ooh look! The letter S
Ooh look! The letter T
Ooh look! The letter U
Ooh look! The letter V
Ooh look! The letter W
Ooh look! The letter X
Ooh look! The letter Y
Ooh look! The letter Z



Comment on this Question and Answer >>>

ASK A QUESTION

More arrays PHP Questions

How do I reverse sort an array by key?

How do we sort an array of names taken from a text file, displaying only unique names?

I have an array of a hundred or so lines, each line has data with "|" separated values. I need to scan through this array, and select the line whose first 5 characters matches a text string. Any ideas or questions?

How do I return all the values in an array?

i need to store a multi-dimensioned array into a file. there is plenty of info. on creating md-arrays but i cant find anything on writing a md-array to a file.



Custom Search