Three forms of PHP array output _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
$BBBB =array ("one" = "AAA", "All" = "BBB");
can only output values value cannot output key
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
";
}

Direct access to array elements:
Copy CodeThe code is as follows:
$arr =array (' w ' = ' wen ', ' j ' = ' jian ', ' b ' = ' bao ');
Echo ($arr [' W ']), '
';//function
Echo ($arr [w]), '
';//function
Echo ($arr [0]), '
';//does not work, do not know why???
Echo ($arr [' J ']), '
';//function
Echo ($arr [j]), '
';//function
Echo ($arr [1]), '
';//does not work, do not know why???
Echo ($arr [' B ']), '
';//function
Echo ($arr [b]), '
';//function
Echo ($arr [2]), '
';//does not work, do not know why???
?>

Output:
Copy CodeThe code is as follows:
Wen
Wen
Jian
Jian
Bao
Bao

Doubtful:
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???
Copy CodeThe code is as follows:
$arr 1=array (' Wen ', ' Jian ', ' bao ');
Echo $arr 1[0], '
', $arr 1[1], '
', $arr 1[2];
?>

Output:
Copy CodeThe code is as follows:
Wen
Jian
Bao

http://www.bkjia.com/PHPjc/327319.html www.bkjia.com true http://www.bkjia.com/PHPjc/327319.html techarticle Copy the code as follows: $BBBB =array ("one" = "AAA", "line" = "BBB"), or//output value can not output key foreach ($bbbb as $color) {echo $color;}//value and Key can output foreach ($bb ...

  • 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.