3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $scores = array( "Kyle" => array(07, 01, 00, 03, 04, 01, 00, 07, 03, 04, 04), "Mike" => array(04, 03, 00, 07, 04, 07, 00, 01, 00, 07, 04), "Will" => array(03, 04, 00, 03, 04, 07, 00, 01, 00, 07, 04), "Johnny" => array(07, 07, 00, 03, 00, 04, 00, 01, 01, 04, 03), "Vasques" => array(03, 01, 00, 03, 04, 07, 00, 01, 00, 07, 07) ); function cmp($a, $b) { return array_sum($b) - array_sum($a); } uasort($scores, "cmp"); $scores = array( "Mike" => array(04, 03, 00, 07, 04, 07, 00, 01, 00, 07, 04), "Kyle" => array(07, 01, 00, 03, 04, 01, 00, 07, 03, 04, 04), "Johnny" => array(07, 07, 00, 03, 00, 04, 00, 01, 01, 04, 03), "Will" => array(03, 04, 00, 03, 04, 07, 00, 01, 00, 07, 04), "Vasques" => array(03, 01, 00, 03, 04, 07, 00, 01, 00, 07, 07) ); //start loop for rows foreach($scores as $key=>$value) { echo "<tr>"; //column for the names echo "<td>$key</td>"; //Total Column echo "<td class='total' align='center' valign='middle'>" . array_sum($scores["Mike"]) . "</td>"; //loop for columns where the score should be displayed for($x=0; $x<count($value); $x++) { echo "<td class='games tip' align='center' valign='middle'>".sprintf('%02d', $value[$x])."</td>"; } echo "</tr>"; }
Output for 4.3.0 - 7.1.0
<tr><td>Mike</td><td class='total' align='center' valign='middle'>37</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>04</td></tr><tr><td>Kyle</td><td class='total' align='center' valign='middle'>37</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>04</td></tr><tr><td>Johnny</td><td class='total' align='center' valign='middle'>37</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>03</td></tr><tr><td>Will</td><td class='total' align='center' valign='middle'>37</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>04</td></tr><tr><td>Vasques</td><td class='total' align='center' valign='middle'>37</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>03</td><td class='games tip' align='center' valign='middle'>04</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>01</td><td class='games tip' align='center' valign='middle'>00</td><td class='games tip' align='center' valign='middle'>07</td><td class='games tip' align='center' valign='middle'>07</td></tr>