Home > Backend Development > PHP Tutorial > php foreach输出二维数组_PHP教程

php foreach输出二维数组_PHP教程

WBOY
Release: 2016-07-13 09:53:27
Original
1634 people have browsed it

php foreach输出二维数组

/*

*标题:foreach输出二维数组

*函数:foreach()

*创建时间:2015年5月16日

*注意事项:

*/

 

//输出一维数组

$array1 = array();

$array1[0] = '楚留香';

$array1[1] = '胡铁花';

$array1[2] = '姬冰燕';

//只有value的情况,也就是只输出值。

foreach ($array1 as $value) {

echo $value.' ';

}

echo '

';

//输出键值对

foreach ($array1 as $key => $value) {

echo $key.':'.$value;

echo '
';

}

echo '

';

//输出二维数组

$array2 = array();

$array2[0]['author'] = '第一个留言者';

$array2[0]['time'] = '留言时间比如20150516 12:00';

$array2[0]['content'] = '留言内容1';

$array2[1]['author'] = '第二个留言者';

$array2[1]['time'] = '留言时间比如20150517 13:00';

$array2[1]['content'] = '留言内容2';

foreach ($array2 as $value) {

//这里的$value其实就是数组

echo "->[".$value['author']."]于".$value['time']."说:
";

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

}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1000538.htmlTechArticlephp foreach输出二维数组 /* *标题:foreach输出二维数组 *函数:foreach() *创建时间:2015年5月16日 *注意事项: */ //输出一维数组 $array1 = array()...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template