The most flexible thing in php is the array. a lot of data is displayed in an array. the array traversal method in PHP is divided into two types: the number index array and the associated array.
The numeric index array is the same as the array in C language. the subscript is 0, 1, 2...
The subscript of the correlated array may be of any type, which is similar to the hash and map structures in other languages.
Method 1: foreach
The code is as follows:
$ Sports = array (
'Football' => 'good ',
'Canonicalization' => '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
The code is as follows:
$ Sports = array (
'Football' => 'good ',
'Canonicalization' => 'very well ',
'Running' => 'not good ');
While (!! $ Elem = each ($ sports )){
Echo $ elem ['key']. ":". $ elem ['value']."
";
}
?>
Output result:
Football: good
Faster Ming: very well
Running: not good
Method 3: list & each
The code is as follows:
$ Sports = array (
'Football' => 'good ',
'Canonicalization' => 'very well ',
'Running' => 'not good ');
While (!! List ($ key, $ value) = each ($ sports )){
Echo $ key. ":". $ value ."
";
}
?>
Output result:
Football: good
Faster Ming: very well
Running: not good