fork download
  1. <?php
  2.  
  3. $angka1 = [[1, 2, 3], [2, 3, 4]]; // 2x3
  4. $angka2 = [[5, 6, 5], [3, 7, 8], [7, 5, 6]]; // 3x3
  5. $hasil = [];
  6.  
  7. // Initialize the result matrix
  8. for ($i = 0; $i < 2; $i++) {
  9. for ($j = 0; $j < 3; $j++) {
  10. $hasil[$i][$j] = 0; // Initialize each element of the result
  11. for ($k = 0; $k < 3; $k++) { // Loop for columns of angka1
  12. $hasil[$i][$j] += $angka1[$i][$k] * $angka2[$k][$j];
  13. }
  14. }
  15. }
  16.  
  17. // Display the result
  18. foreach ($hasil as $baris) {
  19. echo "[" . implode(",", $baris) . "]" . "\n";
  20. }
Success #stdin #stdout 0.02s 25648KB
stdin
Standard input is empty
stdout
[32,35,39]
[47,53,58]