Advertisement
cahyadsn

matrix berpasangan

Aug 17th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2. $criterions=array(
  3.     '1'=>'K1-JP',
  4.     '2'=>'K2-KP',
  5.     '3'=>'K3-JA',
  6.     '4'=>'K4-L'
  7.     );
  8. $relations=array(
  9.     array('1','2',3),
  10.     array('1','3',4),
  11.     array('1','4',2),
  12.     array('2','3',4),
  13.     array('2','4',3),
  14.     array('3','4',5)
  15. );
  16. $rel=array();
  17. foreach($relations as $r){
  18.     $rel[$r[0]][$r[1]]=$r[2];
  19. }
  20. ?>
  21. <table border='1'>
  22. <tr>
  23. <th>Kode</th>
  24. <?php
  25. foreach($criterions as $head){
  26.     echo "<th>{$head}</th>";
  27. }
  28. ?>
  29. </tr>
  30. <?php
  31. foreach($criterions as $kr=>$row_head){
  32.     echo "<tr><th>{$row_head}</th>";
  33.     foreach($criterions as $kc=>$col){
  34.         $val=round($kr<$kc?$rel[$kr][$kc]:($kr==$kc?1:1/$rel[$kc][$kr]),3);
  35.         echo "<td>{$val}</td>";
  36.     }
  37.     echo "</tr>";
  38. }
  39. ?>
  40. </table>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement