I don't have any idea if how I am going to print a pattern, only if I input the number of row and column, help me guys, send your code
<?php
if (isset($_GET['row']) && $_GET['column']) {
$row = $_GET['row'];
$column = $_GET['column'];
$output ="*";
for ($i=$_GET['row']; $i <=1 ; $i++) {
for ($j=$i; $j <=$_GET['column']; $j++) {
$count = $i;
if ($i == $j) {
echo $count. " ";
}else{
echo $count +=4;
} echo "<br>";
}
}
}
?>
here is what I want to have
Enter Row : 5 Enter Column : 4
Output:
*****
*****
*****
*****
You can try the following way with the help of array_fill() and implode(). The array_fill()
function fills an array with values of *
here and implode()
join the stars to a single string.
// $_GET = ['row' => 5, 'column' => 4];
if (isset($_GET['row'], $_GET['column']) && $_GET['row'] > 0 && $_GET['column'] > 0) {
for($i = 0; $i < $_GET['row']; $i++) {
echo implode('', array_fill(0, $_GET['column'], '*')) . PHP_EOL;
}
}