note 19774 added to function.array
| From: | jjm152 at hotmail dot com | Date: | Sun, 10 Mar 2002 23:22:51 +0000 |
| Subject: | note 19774 added to function.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27587@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:
$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://www.php.net/manual/en/function.array.php
http://master.php.net/manage/user-notes.php?action=edit+19774
http://master.php.net/manage/user-notes.php?action=delete+19774
http://master.php.net/manage/user-notes.php?action=reject+19774