html - PHP Associative Array To Table -


i trying sort associative array in ascending in order , transfer html table , stumped @ error. looked guidelines here on , followed instructions on posts:

php display associative array in html table

but still no luck, here attempt:

<?php          function format($g){            array_multisort($g, sort_asc);           echo "<table>";           foreach($g $key=>$row) {               echo "<tr>";               foreach($row $key2=>$row2){                   echo "<td>" . $row2 . "</td>";               }               echo "</tr>";           }           echo "</table>";          }          $bib = array("luke"=>"10",                       "john"=>"30",                       "matt"=>"20",                       "mark"=>"40");          format($bib);        ?> 

my debugger telling me there error @ each loop don't see how wrong unless there syntax error not seeing? error saying invalid argument supplied foreach()

you can try

<?php  function format($data){     array_multisort($data, sort_asc);     echo "<table>";     foreach($data $key => $row) {         echo "<tr>";             echo "<td>" . $key . "</td>";             echo "<td>" . $row . "</td>";         echo "</tr>";     }     echo "</table>"; }  $bib = array(     "luke"=>"10",      "john"=>"30",     "matt"=>"20",     "mark"=>"40" );  format($bib);  ?> 

Comments