[ create a new paste ] login | about

Link: http://codepad.org/RGQVIjWm    [ raw code | output | fork ]

PHP, pasted on Sep 27:
<?php

$rows=array(
    array("diena" => 1, "plkst" => "8:00", "klase" => "10a", "pr" => "Matemātika"),
    array("diena" => 1, "plkst" => "9:00", "klase" => "10a", "pr" => "Matemātika"),
    array("diena" => 2, "plkst" => "8:00", "klase" => "10a", "pr" => "Fizika...."),
    array("diena" => 1, "plkst" => "8:00", "klase" => "9a", "pr" => "Matemātika"),
    array("diena" => 2, "plkst" => "9:45", "klase" => "9a", "pr" => "sports....")
);

$data=array();
foreach($rows as $row){
  $data[$row['diena']][$row['plkst']][$row['klase']] = $row;
}

$dienas=array(1,2,3);
$klases=array("9a","10a");
$laiki=array("8:00","9:00","9:45");

foreach($dienas as $diena){
  echo "Diena: ".$diena."\n";
  foreach($laiki as $laiks){
    echo $laiks." ";
    foreach($klases as $klase){
      if (isset($data[$diena][$laiks][$klase])){
        echo $data[$diena][$laiks][$klase]['pr']." ";
      } else {
        echo ".......... ";
      }
    }
  echo "\n";
  }
echo "\n";
}


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Diena: 1
8:00 Matemātika Matemātika 
9:00 .......... Matemātika 
9:45 .......... .......... 

Diena: 2
8:00 .......... Fizika.... 
9:00 .......... .......... 
9:45 sports.... .......... 

Diena: 3
8:00 .......... .......... 
9:00 .......... .......... 
9:45 .......... .......... 



Create a new paste based on this one


Comments: