ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
tile.php
Go to the documentation of this file.
1 <?php
2 
3 include "../Matrix.php";
4 
22 function tile(&$X, $rowWise, $colWise){
23 
24  $xArray = $X->getArray();
25  print_r($xArray);
26 
27  $countRow = 0;
28  $countColumn = 0;
29 
30  $m = $X->getRowDimension();
31  $n = $X->getColumnDimension();
32 
33  if( $rowWise<1 || $colWise<1 ){
34  die("tile : Array index is out-of-bound.");
35  }
36 
37  $newRowDim = $m*$rowWise;
38  $newColDim = $n*$colWise;
39 
40  $result = array();
41 
42  for($i=0 ; $i<$newRowDim; ++$i) {
43 
44  $holder = array();
45 
46  for($j=0 ; $j<$newColDim ; ++$j) {
47 
48  $holder[$j] = $xArray[$countRow][$countColumn++];
49 
50  // reset the column-index to zero to avoid reference to out-of-bound index in xArray[][]
51 
52  if($countColumn == $n) { $countColumn = 0; }
53 
54  } // end for
55 
56  ++$countRow;
57 
58  // reset the row-index to zero to avoid reference to out-of-bound index in xArray[][]
59 
60  if($countRow == $m) { $countRow = 0; }
61 
62  $result[$i] = $holder;
63 
64  } // end for
65 
66  return new Matrix($result);
67 
68 }
69 
70 
71 $X =array(1,2,3,4,5,6,7,8,9);
72 $nRow = 3;
73 $nCol = 3;
74 $tiled_matrix = tile(new Matrix($X), $nRow, $nCol);
75 echo "<pre>";
76 print_r($tiled_matrix);
77 echo "</pre>";
78 ?>