To access elements of an array, you can use for loop, foreach loop, or while loop. for loop and while loop can be used to assign values to and read array elements. With foreach loop you can only read array elements. However, when using foreach loop to read array elements, you do not need to know the number of elements of the array.
$Arr=array(); //define an array of 10 element
//using for loop to assign values to array elements
//using foreach loop to print all array elements
foreach($Arr as $elem)
//using while loop to print the results of multiplying array elements by 10
Posted by: Ly | post date: 02-05-2013 | Subject: PHP
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: