|
|
Displaying elements of an array by looping
We can loop through an array to display each element of the
array. This code will display all the element of an array. This is very useful
in many occasions where a list is to be displayed. We will see the application
of this in check box value collection.
First we will create an array and then display each element of it.
Here is the code to create and display the value of
the elements of an array.
$a= array("Three",
"two", "Four", "five","ten");
while (list ($key, $val) = each ($a)) {
echo "$key -> $val
<br>";
}
Using Print_r
We can use print_r funciton which returns variables in human readable format. Here is the code.
$a= array("Three", "two", "Four", "five","ten");
print_r($a);
The output of the above code is here.
Array ( [0] => Three [1] => two [2] => Four [3] => five [4] => ten )
There are other way like using foreach function to display the elements of an array
|
| | |
|
|
|
|
|