/*
* Title: foreach Output two-dimensional array
* Function: foreach ()
* Date Created: May 16, 2015
* Precautions:
*/
Output one-dimensional array
$array 1 = array ();
$array 1[0] = ' chu Liu Xiang ';
$array 1[1] = ' hu iron flower ';
$array 1[2] = ' Guibing yan ';
Only the case of value, which 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 array
$array 2 = array ();
$array 2[0][' author '] = ' first message person ';
$array 2[0][' time '] = ' Leave a message like 20150516 12:00 ';
$array 2[0][' content '] = ' message contents 1 ';
$array 2[1][' author '] = ' second message person ';
$array 2[1][' time '] = ' Leave a message like 20150517 13:00 ';
$array 2[1][' content '] = ' message contents 2 ';
foreach ($array 2 as $value) {
The $value here is actually an array.
echo "->[". $value [' author ']. "] To ". $value [' time ']." Said:
";
echo "". $value [' content ']. "
";
}