欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

foreach循环遍历输出数组

程序员文章站 2022-03-24 10:01:29
...
  1. echo '<style>table{border-collapse:collapse;}table,th, td{border: 1px solid black;text-align: center;}td{width: 170px;}</style>';
  2. echo '<table >';
  3. echo '<thead><tr><th>id</th><th>省/市/区</th><th>经度</th><th>纬度</th></tr></thead>';
  4. foreach ($arr as $province) {
  5. echo '<tr><th colspan="5">'.$province['area_name'].'</th></tr>';
  6. foreach ($province['son'] as $city) {
  7. echo '<tr><th>'.$city['area_id'].'</th><th>'.$city['area_name'].'</th><th>'.$city['lng'].'</th><th>'.$city['lat'].'</th></tr>';
  8. foreach ($city['son'] as $area) {
  9. echo '<tr><td>'.$area['area_id'].'</td><td>'.$area['area_name'].'</td><td>'.$area['lng'].'</td><td>'.$area['lat'].'</td></tr>';
  10. }
  11. }
  12. }
  13. echo'</table>';

效果图

foreach循环遍历输出数组