首頁 >php教程 >php手册 >PHP中多维数组的foreach遍历示例

PHP中多维数组的foreach遍历示例

WBOY
WBOY原創
2016-06-06 20:21:471672瀏覽

这篇文章主要介绍了PHP中多维数组的foreach遍历,需要的朋友可以参考下

复制代码 代码如下:


//声明一个三维数组
$info=array(
"user"=>array(
array(1,"zhangsan",20,"nan"),
array(2,"lisi",20,"nan"),
array(3,"wangwu",25,"nv")
),
"score"=>array(
array(1,100,98,95,96),
array(2,56,98,87,84),
array(3,68,75,84,79)
),
"connect"=>array(
array(1,'2468246',"salkh@bbs.com"),
array(2,'343681643',"aikdki@sina.com"),
array(3,'3618468',"42816@qq.com")
)
);
//循环遍历,输出一个表格
foreach($info as $tableName=>$table){
echo "

";
echo "";//以每个数组的键值作为表名
foreach($table as $row){
echo "";
foreach($row as $col){
echo "";
}
echo "";
}
echo "

".$tableName."

".$col."
";
}
?>
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn