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
Copy codeThe 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: each
Copy 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 & each
Copy 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