1. 云栖社区>
  2. PHP教程>
  3. 正文

使用foreach遍历三维数组

作者:用户 来源:互联网 时间:2017-12-01 14:22:34

遍历数组三维foreach使用

使用foreach遍历三维数组 - 摘要: 本文讲的是使用foreach遍历三维数组, <?php//使用foreach遍历3维出数组,以表格的形式输出$wage=array("市场部"=>array(array(1,"高某","市场部经理",50000),array(2,"洛某","职员",5000),arra

<?php
//使用foreach遍历3维出数组,以表格的形式输出
$wage=array(
"市场部"=>array(
array(1,"高某","市场部经理",50000),
array(2,"洛某","职员",5000),
array(3,"峰某","职员",6000)
),
"财务部"=>array(
array(1,"李某","财务部经理",10000),
array(2,"钱某","职员",2000),
array(3,"吴某","职员",3000)

),
"产品部"=>array(
array(1,"周某","财务部经理",20000),
array(2,"赵某","职员",7000),
array(3,"孙某","职员",8000)
)
);


foreach($wage as $sector => $table){
echo "<table width='800' align='center' border='10'>";
echo "<caption><h2>{$sector} 10月份工资表</h2></caption>";
echo "<tr bgcolor='#dddddd'>";
echo "<th>编号</th>";
echo "<th>姓名</th>";
echo "<th>职位</th>";
echo "<th>工资</th>";
echo "</tr>";
foreach($table as $row){
echo "<tr align='center'>";
foreach($row as $col){
echo "<td>{$col}</td>";
}
echo "</tr>";
}
echo "</table><br>";
}
?>

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索遍历 , 数组 , 三维 , foreach 使用 ,以便于您获取更多的相关知识。