Foreach嵌套Foreach

<?php
$db=new MySQLi("localhost","账号","密码","数据库名");   //链接数据库
$sql=$db->query("select * from 表名");   //执行SQL语句查询
$arrt=$sql->fetch_all();
 echo"<table border='1' width='100%'>";
 $attr=array(要输出的列数,要输出的列数,要输出的列数);
foreach($arrt as $v)   //遍历数组
{
    
      echo "<tr>";
      foreach($attr as $q)
      {
      echo"<td>$v[$q]</td> ";
      }
      echo"</tr>"; 
}

echo "</table>";
?>
原文地址:https://www.cnblogs.com/zbxiaoxu/p/5478791.html