This article is a detailed analysis of the three forms of the output of PHP arrays (array), which requires a friend's reference
The code is as follows:
$BBBB =array ("one" = "AAA", "All" and "BBB");//Only output value cannot output Keyforeach ($bbbb as $color) {echo $color;} Both value and key can output foreach ($bbbb as $key + $value) {echo $key. = ". $value;} Both value and key can be output while ($color =each ($BBBB)) {echo $color [' key '];} or while (list ($key, $value) =each ($BBBB) {echo "$key: $value <br>";}
Direct access to array elements:
The code is as follows:
<?php$arr=array (' w ' = ' wen ', ' j ' = ' jian ', ' b ' = ' bao '), Echo ($arr [' W ']), ' <br/> ';//function Echo ($arr [W] ), ' <br/> ';//function echo ($arr [0]), ' <br/> ';//do not work, do not know why??? Echo ($arr [' J ']), ' <br/> ';//function Echo ($arr [j]), ' <br/> ';//function Echo ($arr [1]), ' <br/> ';//do not work, do not know why??? Echo ($arr [' B ']), ' <br/> ';//function Echo ($arr [b]), ' <br/> ';//function Echo ($arr [2]), ' <br/> ';//do not work, do not know why???? >
Output:
The code is as follows:
Wen
Wen
Jian
Jian
Bao
Bao
Doubt:
Accesses an associative array element,
1, [] in the "key" can not be used without quotation marks ("") can also be accessed???
2, array index Access does not work???
The code is as follows:
<?php$arr1=array (' Wen ', ' Jian ', ' bao '), Echo $arr 1[0], ' <br/> ', $arr 1[1], ' <br/> ', $arr 1[2];? >
Output:
The code is as follows:
Wen
Jian
Bao