Generazione di una tabella HTML con un singolo ciclo in PHP

Generiamo una tabella con un singolo ciclo, scrivendo manualmente negli tag td gli elementi del sotto-array:

php<?php
  echo '<table>';
  foreach ($arr as $user) {
    echo '<tr>';
    
    echo "<td>{$user['name']}</td>";
    echo "<td>{$user['age']}</td>";
    echo "<td>{$user['salary']}</td>";
    
    echo '</tr>';
  }
  echo '</table>';
?>

Questo metodo ci darà un controllo più completo, sia sull'ordine delle celle, sia sulla possibilità di aggiungere dati aggiuntivi in ogni cella, ad esempio, in questo modo:

php<?php
  echo '<table>';
  foreach ($arr as $user) {
    echo '<tr>';
    
    echo "<td>{$user['name']}</td>";
    echo "<td>{$user['age']} anni</td>";
    echo "<td>{$user['salary']} dollari</td>";
    
    echo '</tr>';
  }
  echo '</table>';
?>