This article describes how to use the foreach, list, and each functions in PHP to traverse arrays: Method 1: foreach & lt ;? Php $ sportsarray (football & gt; good, Discovery Ming & gt; verywell, running & gt; notgood); foreach ($ sportsas $ key & gt; $ valu
This article describes how to use the foreach, list, and each functions for traversing arrays in PHP:
Method 1: foreach
$ Sports = array (
Football => good,
Faster Ming => very well,
Running => not good );
Foreach ($ sports as $ key => $ value ){
Echo $ key. ":". $ value ."
";
?>
Output result:
Football: good
Faster Ming: very well
Running: not good
Method 2: each
$ Sports = array (
Football => good,
Faster Ming => very well,
Running => not good );
While ($ elem = each ($ sports )){
Echo $ elem [key]. ":". $ elem [value]."
";
?>
Method 3: list & each
$ Sports = array (
Football => good,
Faster Ming => very well,
Running => not good );
While (list ($ key, $ value) = each ($ sports )){
Echo $ key. ":". $ value ."
";
?>