This article is a detailed analysis and introduction to the three forms of PHP array (array) output. For those who need it, please refer to
The code is as follows:
$bbbb=array("11"=>"aaa","22"=>"bbb"); //只能输出值value不能输出key foreach($bbbb as $color) { echo $color; } //value与key都可输出 foreach($bbbb as $key=>$value) { echo $key."=>".$value; } //value与key都可输出 while($color=each($bbbb)){ echo $color['key']; } 或 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/>';//起作用 echo($arr[w]),'<br/>';//起作用 echo($arr[0]),'<br/>';//不起作用,不知为什么??? echo($arr['j']),'<br/>';//起作用 echo($arr[j]),'<br/>';//起作用 echo($arr[1]),'<br/>';//不起作用,不知为什么??? echo($arr['b']),'<br/>';//起作用 echo($arr[b]),'<br/>';//起作用 echo($arr[2]),'<br/>';//不起作用,不知为什么??? ?>
Output:
The code is as follows:
wen
wen
jian
jian
bao
bao
Suspicious points:
Accessing associative array elements,
1. Can the "key" in [ ] be accessed without using quotation marks ("")? ? ?
2. Array index access doesn’t work? ? ?
The code is as follows:
<?php $arr1=array('wen','jian','bao'); echo $arr1[0],'<br/>',$arr1[1],'<br/>',$arr1[2]; ?>
Output:
The code is as follows:
wen
jian
bao
The above is the detailed content of Methods for php array output. For more information, please follow other related articles on the PHP Chinese website!