Matris Multiplication

mail@pastecode.io avatar
unknown
php
2 years ago
707 B
11
Indexable
Never
<?php
    $matris1 = [
        [1,  2,  3,  4],
        [5,  6,  7,  8],
        [9, 10, 11, 12],
        [13, 14, 15, 16]

    ];
    $matris2 = [
        [1,  2,  3,  4],
        [5,  6,  7,  8],
        [9, 10, 11, 12],
        [13, 14, 15, 16] 
    ];
    $Multiplication = null;

    {
    for($i=0 ; $i < count($matris1); $i++ ){
        for( $j = 0 ; $j < count($matris1[$i]) ; $j++){
            for( $k = 0 ; $k < count($matris2); $k++ ) 
                if(count($matris1[$j]) == count($matris2)){
                     $Multiplication[$i][$j] += $matris1 [$i][$k] * $matris2 [$k][$j] ; 
                }     
        }
    }

    print_r($Multiplication); }
    ?>