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

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



ASK A QUESTION

More arrays PHP Questions

How do I generate an associative array like Jan => 10, Feb =>20 etc from a mysql table of 2 columns, month and val ?

How do I reverse sort an array by key?

what is a array?

to check if the value is an array

when we retrieve values from db and show in drop-down list then how can i get selected particular value from drop-down so that programe will go next page??



Custom Search