In PHP, arrays are divided into two types: Numerical index arrays and associated arrays.
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
CopyCode The Code is as follows: <? PHP
$ Sports = array (
'Football' => 'good ',
'Canonicalization' => 'very well ',
'Running' => 'not good ');
Foreach ($ sports as $ key => $ value ){
Echo $ key. ":". $ value. "<br/> ";
}
?>
Output result:
Football: Good
Faster Ming: Very well
Running: Not good
Method 2: EachCopy codeThe Code is as follows: <? PHP
$ Sports = array (
'Football' => 'good ',
'Canonicalization' => 'very well ',
'Running' => 'not good ');
While (!! $ ELEM = each ($ sports )){
Echo $ ELEM ['key']. ":". $ ELEM ['value']. "<br/> ";
}
?>
Output result:
Football: Good
Faster Ming: Very well
Running: Not good
Method 3: List & eachCopy codeThe Code is as follows: <? PHP
$ Sports = array (
'Football' => 'good ',
'Canonicalization' => 'very well ',
'Running' => 'not good ');
While (!! List ($ key, $ value) = each ($ sports )){
Echo $ key. ":". $ value. "<br/> ";
}
?>
Output result:
Football: Good
Faster Ming: Very well
Running: Not good