Foreach loop syntax
| From: | Keith Devens | Date: | Tue, 01 Aug 2000 01:46:43 +0000 |
| Subject: | Foreach loop syntax | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-9335@lists.php.net to get a copy of this message | ||
Just wondering why the following syntax (example from the manual):
foreach ($arr as $value) {
echo "Value: $value<br>\n";
}
was chosen over a 'more traditional':
foreach $cheese ($cheeses) {
echo "My favorite cheese is $cheese<br>\n";
}
Was it so that you could do something like this (also from the manual):
foreach ($arr as $key => $value) {
echo "Key: $key; Value: $value<br>\n";
}
and get the key in addition to the value?
Any insight into the design choices of a language is always good :)
Thanks!
Keith