czaroentoro

Array Row Span Table

Sep 30th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. <?php
  2. $qresult = array(['kotaa', 'sd1'],['kotaa','sd2'],['kotab','sd3'], ['kotab','sd4'], ['kotab','sd5']);
  3.  
  4. $cities = array();
  5. foreach($qresult as $city){
  6.       if(!array_key_exists($city[0], $cities)){
  7.             $cities[$city[0]] = array();
  8.             $cities[$city[0]][] = $city[1];
  9.      } else {
  10.             $cities[$city[0]][]  = $city[1];
  11.      }
  12. }
  13. echo "<table>";
  14. foreach($cities as $key => $city){
  15.    foreach($city as $innerkey => $school){
  16.         if($innerkey == 0){
  17.             echo "<tr><td rowspan =".sizeof($city).">$key</td><td>$school</td></tr>";
  18.         } else {
  19.             echo "<tr><td>$school</td></tr>";
  20.         }
  21.     }
  22. }
  23. echo "</table>";
Advertisement
Add Comment
Please, Sign In to add comment