apress.com">http://www.apress.com
http://www.php.net http://www.apache.org The second variation is well-suited for working with both the key and value of an
array. The syntax follows:
foreach (array_expr as $key => $value) {
statement
}
Revising the previous example, suppose that the $links array contains both a link
and a corresponding link title:
$links = array("The Apache Web Server" => "www.apache.org",
"Apress" => "www.apress.com",
"The PHP Scripting Language" => "www.php.net");
Each array item consists of both a key and a corresponding value. The foreach
statement can easily peel each key/value pair from the array, like this:
echo "
Online Resources:
";
foreach($links as $title => $link) {
echo "
$title";
}
The result would be that each link is embedded under its respective title, like this:
Online Resources:
The Apache Web Server Apress The PHP Scripting Language There are other variations on this method of key/value retrieval, all of which are
introduced in Chapter 5.
CHAPTER 3 ?– PHP BASICS 107
The break and goto Statements
Encountering a break statement will immediately end execution of a do.
Pages:
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191