Home >Backend Development >PHP Tutorial >Detailed explanation of the three forms of php array (array) output_PHP tutorial

Detailed explanation of the three forms of php array (array) output_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:09:14926browse

Copy code The code is as follows:

$bbbb=array("11"=>"aaa","22"=> "bbb");
//Can only output value value but not key
foreach($bbbb as $color)
{
 echo $color;
}
//value Both 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
";
}

Direct access to array elements:
Copy code The code is as follows:

$arr=array('w'=>'wen ','j'=>'jian','b'=>'bao');
echo($arr['w']),'
';//It works
echo($arr[w]),'
';//It works
echo($arr[0]),'
';//It doesn’t work Function, I don’t know why? ? ?
echo($arr['j']),'
';//It works
echo($arr[j]),'
';// It works
echo($arr[1]),'
';//It doesn't work, I don't know why? ? ?
echo($arr['b']),'
';//It works
echo($arr[b]),'
';// It works
echo($arr[2]),'
';//It doesn't work, I don't know why? ? ?
?>

Output:
Copy code The code is as follows:

wen
wen
jian
jian
bao
bao

Suspicious point:
Accessing associative array elements,
1. Can the "key" in [ ] be accessed without using quotation marks ("")? ? ?
2. Array index access doesn’t work? ? ?
Copy code The code is as follows:

$arr1=array('wen' ,'jian','bao');
echo $arr1[0],'
',$arr1[1],'
',$arr1[2];
?>

Output:
Copy code The code is as follows:

wen
jian
bao

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327319.htmlTechArticleCopy the code as follows: $bbbb=array("11"="aaa","22"="bbb "); //Only value can be output but not key foreach($bbbb as $color) { echo $color; } //Both value and key can be output foreach($bb...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn