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 () ...