i wrote this code to fill true value in the 2D Array but i got only one True value.
<?php
$twoD = array(array());
$res = array(2, 3);
$x_len = 4;
$y_len = 4;
// fill the array
for ($x = 0; $x < $x_len; $x++) {
for ($y = 0; $y < $y_len; $y++) {
for ($r = 0; $r < count($res); $r++) {
if ($y == $res[$r] and $x == $res[$r]) {
$twoD[$x][$y] = 'True';
} else {
$twoD[$x][$y] = 'False';
}
}
}
}
// print the array
for ($r = $x_len; $r > 0; $r--) {
for ($c = 0; $c < $y_len; $c++)
echo $twoD[$r - 1][$c];
echo "<br/>";
}
?>
i got this result:
FalseFalseFalseTrue
FalseFalseFalseFalse
FalseFalseFalseFalse
FalseFalseFalseFalse
the result must be like this because $res = array(2, 3);
FalseFalseFalseTrue
FalseFalseTrueFalse
FalseFalseFalseFalse
FalseFalseFalseFalse
Please help and thank you in advance.
Safoh