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

to check if the value is an array

How do I pick a random value from an array?

HOW CAN I DELETE ALL THE ELEMENT OF THE ARRAY

how can you reset an array in PHP

How do I add to the end of an array and know how large the array is?



Custom Search