大家帮助我看下这个二维数组怎么通过foreach循环打印

chb89888404 2009-08-16 12:43:22

<?php
$array=array(
array("id"=>"1","name"=>"王永平","date"=>"2008-8-7"),
array("id"=>"2","name"=>"韩文丽","date"=>"2008-8-8"),
array("id"=>"3","name"=>"曹雅丽","date"=>"2008-9-9"),
array("id"=>"4","name"=>"董盼红","date"=>"2008-8-10"),
);

?>

大家帮助我看下这个二维数组怎么通过foreach循环打印出里面所有“name”对应的值,我昨天试了一直没有成功,谢谢
...全文
574 点赞 收藏 9
写回复
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
ms_X0828 2009-08-17
输出name:

foreach ($array as $a){
echo $a["name"]."<br/>";
}

输出所有信息:
foreach ($array as $a){
foreach ($a as $val){
echo $val." ";
}
echo "<br/>";
}
回复
llj480028 2009-08-17
foreach($array as $key=>$value){
foreach($value as $key1=>$value1)
print $value1;print "<br>";
}
测一下看看,应该可以的~
回复
llj480028 2009-08-17
foreach($array as $key=>$value){
foreach($value as $key1=>$value1)
print $value1;print "<br>";
}
测一下看看,应该可以的~
回复
llj480028 2009-08-17
foreach($array as $key=>$value){
foreach($value as $key1=>$value1)
print $value1;print "<br>";
}
测一下看看,应该可以的~
回复
wzftop 2009-08-17
foreach ($array as $arr)
{
echo $arr['name']."<br/>";

}
回复
CunningBoy 2009-08-17
foreach($array as $v1){
echo $v1['name']."\r\n";
}
回复
Ehlonna 2009-08-16
foreach ($array as $v) {
echo $v['name'] . "<br />";
}
回复
kondykuang 2009-08-16
"a1"=> 粘贴了忘了改
回复
kondykuang 2009-08-16
<?php
$array=array(
array("id"=>"1","name"=>"王永平","date"=>"2008-8-7"),
array("id"=>"2","name"=>"韩文丽","date"=>"2008-8-8"),
array("id"=>"3","name"=>"曹雅丽","date"=>"2008-9-9"),
array("id"=>"4","name"=>"董盼红","date"=>"2008-8-10"),
);

?>

//你这我也不知道怎么用foreach遍历。好像只能一个一个打。
最好写成这样。
$arrayname=array(
"a1"=>array("id"=>"1","name"=>"王永平","date"=>"2008-8-7"),
"a1"=>array("id"=>"2","name"=>"韩文丽","date"=>"2008-8-8"),
"a1"=>array("id"=>"3","name"=>"曹雅丽","date"=>"2008-9-9"),
"a1"=>array("id"=>"4","name"=>"董盼红","date"=>"2008-8-10"),
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告