note 19774 modified in function.array by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 13:57:08 +0000 |
| Subject: | note 19774 modified in function.array by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79967@lists.php.net to get a copy of this message | ||
The easiest way to "list" the values of either a normal 1 list array or a multi
dimensional array is to use a foreach() clause.
Example for 1 dim array:
<?php
$arr = array( 1, 2, 3, 4, 5 );
foreach ( $arr as $val ) {
echo "Value: $Val\n";
}
?>
For multi dim array:
<?php
$arr = array( 1 => 'one', 2 => 'two', 3 => 'three', 4
=> 'four, 5 => 'five');
foreach ( $arr as $key => $value ) {
echo "Key: $key, Value: $value\n";
}
?>
This is quite possibly the easiest way i've found to iterate through an array.
--was--
The easiest way to "list" the values of either a normal 1 list array or a multi
dimensional array is to use a foreach() clause.
Example for 1 dim array:
$arr = array( 1, 2, 3, 4, 5 );
foreach ( $arr as $val ) {
echo "Value: $Val\n";
}
For multi dim array:
$arr = array( 1 => 'one', 2 => 'two', 3 => 'three', 4
=> 'four, 5 => 'five');
foreach ( $arr as $key => $value ) {
echo "Key: $key, Value: $value\n";
}
This is quite possibly the easiest way i've found to iterate through an array.
http://php.net/manual/en/function.array.php