Methods for the output of the PHP array

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.