I need to create the Letter T with PHP code: This is what I have so far but can't seem to figure how to just have the asterisks on the top two lines in order to extend the top of the T:
<?php
echo "<pre>";
for ($row > 2; $row < 15; $row++) {
for ($column = 2; $column < 12; $column++) {
if (($row < 2 || $row < 2) || ($column < 2 || $column >= 6)) {
echo "*";
}
else echo " ";
}
echo "
";
}
echo "</pre>";
?>
start your for loop with $row = 0
for ($row = 0; $row < 15; $row++) {
you were ignoring the first 2 lines and only drawing the vertical line
Also ($row < 2 || $row < 2)
is the same as $row < 2
You have several bugs in your code.
for ($row > 2; $row < 15; $row++) {
for ($column = 2; $column < 12; $column++) {
why do you use $row > 2
and $column = 2
? Just start from zero.
if (($row < 2 || $row < 2) || ($column < 2 || $column >= 6)) {
Why do you check if $row < 2
is true or $row < 2
is true if they are the same?
Here is an example:
echo "<pre>";
for($i=0; $i <= 10; $i++){
for($j = 0; $j < 10; $j++){
if($i > 2 && ($j < 3 || $j > 6)){
echo " ";
}else{
echo "*";
}
}
echo "
";
}
for ($row > 2; $row < 15; $row++) {
This condition is wrong, and should be:
for ($row = 0; $row < 15; $row++) {
And:
if (($row < 2 || $row < 2)
is wrong and doesn't do what you probably think it does.
The code in the thread j08691 linked you to, contains the correct solution and you could use that:
<?php
echo "<pre>";
for ($row = 0; $row < 15; $row++) {
for ($column = 0; $column <10; $column++) {
if (($row < 1 || $row > 15) ||( $column == 4)) {
echo "*";
}
else echo " ";
}
echo "
";
}
echo "</pre>";
?>
See the live demo.