Make your own free website on Tripod.com

Visit the Official PHP Website

Search this Site

PHP Programming

By James N Hitz

Traversing an array

Printing all the contents of an array is called traversing an arry. This requires the understanding of iteration discussed in the next lseeson Although I will not go to great length to explain what is actually going on, I figure it is best to show you how to traverse an array here and then explain it later.

If you like however, you can click here to on to Lesson 4 where control structures are discussed and then come back. I recommend you ignore the nitty gritty for now and come back to this later.

That notwithstanding, this is how you traverse an array:

while(each($fruits)){
		echo current($fruits)." <br>";
		}

This will print all the contents of an array (list or associative), one on each line. There are other ways of traversing arrays but let's cool it for now. Right?

There is no single PHP function that prints the whole array, but PHP has a myriad of other in-built functions for manipulating arrays. Up Next: PHP's array-manipulation functions...

<< Associative Arrays | PHP Functions >>

JamHitz Productions