Turning the values of a multidimensional PHP array

0

I am doing an exercise for a class in which I am asked to create a nxn table with certain requirements, diagonal will show asterisks, the sum of the positions of the rows and columns will be shown at the top, and below random numbers will be shown between 10 and 20, and then I have to create a function that inverts these values, but the program is not able to do it with more than 13filasx13columns, to see if someone can help me, since I do not see the error, In my eyes, the code is correct and the professor has not been able to find anything ...

<?php
function creaMatriu($n){
    echo "Matriu";
    for ($fila = 0; $fila < $n; $fila++){
        for ($columna = 0; $columna < $n; $columna++){
            if ($fila == $columna){
                $matriu[$fila][$columna] = "*";
            }elseif ($fila > $columna){
                $matriu[$fila][$columna] = mt_rand(10,20);
            }else{
                $matriu[$fila][$columna] = $columna + $fila;
            }

        }
    }
    mostraMatriu($matriu, $n);
    echo "Matriu girada";
    giraMatriu($matriu, $n);
}

function mostraMatriu($matriu, $n)
{
    echo "<table border = 1 width=400>";
    for ($fila = 0; $fila < $n; $fila++) {
        echo "<tr>";
        for ($columna = 0; $columna < $n; $columna++) {
            if ($fila == $columna) {
                echo "<td align='center'>";
                echo $matriu[$fila][$columna];
                echo "</td>";
            } elseif ($fila > $columna) {
                echo "<td align='center'>";
                echo $matriu[$fila][$columna];
                echo "</td>";
            } else {
                echo "<td align='center'>";
                echo $matriu[$fila][$columna];
                echo "</td>";
            }

        }
        echo "</tr>";
    }
    echo "</table>";
    echo "<br>";
}

function giraMatriu($matriu, $n){
    for ($fila = 0; $fila < $n; $fila++){
        for ($columna = 0; $columna < $n; $columna++){
            if ($fila == $columna){
                $matriuGirada[$fila][$columna] = "*";
            }elseif ($fila > $columna){
                $matriuGirada[$fila][$columna] = $matriu[$columna][$fila];
            }else{
                $matriuGirada[$fila][$columna] = $matriu[$columna][$fila];
            }
        }
    }
    mostraMatriu($matriuGirada,$n);
}

creaMatriu(16);
?>
    
asked by THR4SH3RP0L0 23.01.2018 в 19:13
source

0 answers