Three forms of php array output are described in detail. Copy the code as follows: $ bbbbarray (11aaa, 22bbb); only the value can be output, and keyforeach ($ bbbbas $ color) {echo $ color ;} both value and key can output foreach ($ bb
The code is as follows:
$ Bbbb = array ("11" => "aaa", "22" => "bbb ");
// Only output values, values, and Keys
Foreach ($ bbbb as $ color)
{
Echo $ color;
}
// Both value and key can be 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
";
}
Directly access the array elements:
The code is as follows:
$ Arr = array ('W' => 'wen', 'J' => 'jian ',' B '=> 'bao ');
Echo ($ arr ['w']),'
'; // Takes effect
Echo ($ arr [w]),'
'; // Takes effect
Echo ($ arr [0]),'
'; // Does not work. why ???
Echo ($ arr ['J']),'
'; // Takes effect
Echo ($ arr [j]),'
'; // Takes effect
Echo ($ arr [1]),'
'; // Does not work. why ???
Echo ($ arr ['B']),'
'; // Takes effect
Echo ($ arr [B]),'
'; // Takes effect
Echo ($ arr [2]),'
'; // Does not work. why ???
?>
Output:
The code is as follows:
Wen
Wen
Jian
Jian
Bao
Bao
Question:
Access associated array elements,
1. the "key" in [] can also be accessed without quotation marks ???
2. array index access does not work ???
The code is as follows:
$ Arr1 = array ('wen', 'jian ', 'bao ');
Echo $ arr1 [0],'
', $ Arr1 [1],'
', $ Arr1 [2];
?>
Output:
The code is as follows:
Wen
Jian
Bao
The http://www.bkjia.com/PHPjc/327319.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/327319.htmlTechArticle code is as follows: $ bbbb = array ("11" = "aaa", "22" = "bbb "); // only output value cannot output key foreach ($ bbbb as $ color) {echo $ color;} // both value and key can output foreach ($ bb...