function printMatrix($matrix) {
$rows = count($matrix);
$cols = count($matrix[0]);
for ($i = 0; $i < $rows; $i++) {
for ($j = 0; $j < $cols; $j++) {
printf("%4d", $matrix[$i][$j]);
}
echo "\n";
}
}
function generateRandomMatrix($rows, $cols) {
$matrix = array_fill(0, $rows, array_fill(0, $cols, 0));
for ($i = 0; $i < $rows; $i++) {
for ($j = 0; $j < $cols; $j++) {
$matrix[$i][$j] = rand(1, 100);
}
}
return $matrix;
}
$matrix = generateRandomMatrix(4, 5);
printMatrix($matrix);
/*
run:
42 93 55 29 3
13 9 30 49 6
70 49 70 33 7
43 17 11 47 73
*/