PHP foreach output two-dimensional array _php tutorial

Source: Internet
Author: User
Tags php foreach

PHP foreach output two-dimensional array


/*

* Title: foreach output two-dimensional array

* Function: foreach ()

* Date of Creation: May 16, 2015

* Precautions:

*/

Output one-dimensional arrays

$array 1 = array ();

$array 1[0] = ' chu Liu Xiang ';

$array 1[1] = ' Iron flower ';

$array 1[2] = ' Guibing yan ';

Only the case of value, that is, the output value only.

foreach ($array 1 as $value) {

echo $value. ' ';

}

Echo '

';

Output key-value pairs

foreach ($array 1 as $key = = $value) {

echo $key. ': ' $value;

Echo '
';

}

Echo '

';

Output two-dimensional arrays

$array 2 = array ();

$array 2[0][' author '] = ' first message person ';

$array 2[0][' time ' = ' message times like 20150516 12:00 ';

$array 2[0][' content '] = ' message 1 ';

$array 2[1][' author '] = ' second message person ';

$array 2[1][' time ' = ' message times like 20150517 13:00 ';

$array 2[1][' content '] = ' message 2 ';

foreach ($array 2 as $value) {

The $value here is actually an array.

echo "->[". $value [' author ']. "] To ". $value [' time ']." Said:
";

echo "". $value [' content '].
";

}

http://www.bkjia.com/PHPjc/1000538.html www.bkjia.com true http://www.bkjia.com/PHPjc/1000538.html techarticle php foreach output two-dimensional array/* Title: foreach output two-dimensional array * function: foreach () * Creation time: May 16, 2015 * NOTE: *//output one-dimensional array $array 1 = array () ...

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