PHP学习 array()数组练习-foreach循环3维数组

使用for循环循环3维数组也可以循环。但是效率和代码量都没有foreach简单。简洁。所以使用了foreach来遍历!

foreach遍历3维数组
 //foreach循环一个3维数组
  /*
  $biaoge=array(
      "市场部"=>array(
            array(1,"gaomou1","jingli11",4000),
            array(2,"gaomou2","jingli22",4000),
            array(3,"gaomou3","jingli33",4000)
         ),
      "客服部"=>array(
            array(1,"gao1","li11",4000),
            array(2,"gao2","li22",4000),
            array(3,"gao3","li33",4000)
        ),
      "业务部"=>array(
             array(1,"mou1","jing11",4000),
             array(2,"mou2","jing22",4000),
             array(3,"mou3","jing33",4000)
        )
   );

  foreach($biaoge as $key=>$value){
  echo '<table align="center" width="600" border="1">';
  echo '<caption>联系表</caption>';
  echo '<tr bgcolor="#dddddd">';
  echo '<th>标号</th><th>名字</th><th>职位</th><th>工资</th></tr>';
  foreach($value as $row){
      if($row%2==0){
      $bg="#ffffff";
   }else{
       $bg="#dddddd";
   }
   echo '<tr bgcolor='.$bg.'>';
   foreach($row as $col){
       echo '<td>'.$col.'</td>';   
   }
   echo '</tr>';
  }
  echo '</table>';
     }
  echo "<pre>";
  print_r($biaoge);
  echo "</pre>";

相关文章

仅有 1 条评论
  1. sprityaoyao

    数组的这个操作方法在emlog用的很多

    sprityaoyao 回复
发表新评论