Im trying to create a 2D array with a specific number of rows and cols which I have stored as the variable $n ; so if $n was 5, I would have 5 rows and 5 cols, all with random numbers. I have created a for loop (as shown below) that generates the correct amount of rows but I cannot figure out how to do the same with the columns at the same time. The code I have at the moment is shown below.
<?php
$n = 3;
for($i=0; $i<=$n; $i++) {
$value[$i][0] = rand(1,20);
$value[$i][1] = rand(1,20);
$value[$i][2] = rand(1,20);
$value[$i][3] = rand(1,20);
}
print "<table>";
for($j=0; $j<$n; $j++) { // Runs the loop times $n
print "<tr>";
for($k=0; $k<$n; $k++) { // Runs the loop times $n
print "<td>" . $value[$j][$k] . "</td>";
}
print "</tr>";
}
print "</table>";
?>
Any help would be appreciated in learning to create this loop of the array. Thanks in advance.