PHP arrays (array) output of three forms of detailed _php tips

Source: Internet
Author: User
Copy Code code as follows:

$BBBB =array ("One" => "AAA", "=>" "BBB");
can only output values value cannot output key
foreach ($bbbb as $color)
{
Echo $color;
}
Both value and key can be exported
foreach ($bbbb as $key => $value)
{
echo $key. " => ". $value;
}

Both value and key can be exported
while ($color =each ($bbbb)) {
echo $color [' key '];
}
Or
while (list ($key, $value) =each ($BBBB)) {
echo "$key: $value <br>";
}

To access an array element directly:
Copy Code code 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/> '/does not work, do not know why???
Echo ($arr [' J ']), ' <br/> '/function
Echo ($arr [j]), ' <br/> '/function
Echo ($arr [1]), ' <br/> '/does not work, do not know why???
Echo ($arr [' B ']), ' <br/> '/function
Echo ($arr [b]), ' <br/> '/function
Echo ($arr [2]), ' <br/> '/does not work, do not know why???
?>

Output:
Copy Code code as follows:

Wen
Wen
Jian
Jian
Bao
Bao

Doubtful points:
To access an associative array element,
1, [] in the "key" can be used without quotation marks ("") is also accessible???
2, the array index Access does not work???
Copy Code code as follows:

<?php
$arr 1=array (' Wen ', ' Jian ', ' bao ');
Echo $arr 1[0], ' <br/> ', $arr 1[1], ' <br/> ', $arr 1[2];
?>

Output:
Copy Code code 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.