Skip to content

Instantly share code, notes, and snippets.

@adzimzf
Last active May 30, 2016 14:08
Show Gist options
  • Save adzimzf/cc3c1926114738b6251807f97d622bd7 to your computer and use it in GitHub Desktop.
Save adzimzf/cc3c1926114738b6251807f97d622bd7 to your computer and use it in GitHub Desktop.
<?php
//mendefinisikan operan 1 dan 2
$operand_1 = array(array(1,3,4),array(4,7,8),array(3,1,3));
$operand_2 = array(array(4,6,9),array(5,2,0),array(3,6,7));
for ($baris=0; $baris < count($operand_1); $baris++) {
for ($kolom=0; $kolom < count($operand_1); $kolom++) {
echo $operand_1[$baris][$kolom]." ";
}
echo PHP_EOL;
}
echo PHP_EOL;
for ($baris=0; $baris < count($operand_2); $baris++) {
for ($kolom=0; $kolom < count($operand_2); $kolom++) {
echo $operand_2[$baris][$kolom]." ";
}
echo PHP_EOL;
}
//mendefinisikan array hasil
$hasil = array(array(0,0,0),array(0,0,0),array(0,0,0));
//hitung matrik
for ($baris=0; $baris < count($hasil); $baris++) {
for ($kolom=0; $kolom < count($hasil); $kolom++) {
for ($l=0; $l < count($hasil); $l++) {
$hasil[$baris][$kolom]=$hasil[$baris][$kolom]+$operand_1[$baris][$l]*$operand_2[$l][$kolom];
}
}
}
echo "\nHasil nya adalah \n";
for ($baris=0; $baris < count($hasil); $baris++) {
for ($kolom=0; $kolom < count($hasil); $kolom++) {
echo $hasil[$baris][$kolom]." ";
}
echo PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment