r/code • • Nov 18 '19

Need some simple PHP coding explained.

So we (my class) is getting started with PHP coding and were given the task to write a program that would write the following text:

(Watch image)

For most of you this is going to be easy, but I have no clue where to begin. So i checked what the final answer is supposed to be:

<?php          $rowNumber = 10;        while( $rowNumber > 0 ) {          $columnNumber = 0;          while ( $columnNumber < $rowNumber )          {                    echo "\*";                    $columnNumber++;          }          echo "\\n";          $rowNumber--;        }?>

I just don't understand how I'm supposed to see this. Anyone got any advice for how I can practice these kinds of tasks?

0 Upvotes

6 comments sorted by

View all comments

4

u/4gotn1 Nov 18 '19
<?php
$rowNumber = 10;
while( $rowNumber > 0 ) {
    $columnNumber = 0;
    while( $columnNumber < $rowNumber ) {
        echo "\*";
        $columnNumber++;
    }
    echo "\\n";
    $rowNumber--;
}?>

I just don't understand how I'm supposed to see this.

Literally? There are online sandboxes if you need to test it out.
Or do you need someone to explain it step-by-step?

Anyone got any advice for how I can practice these kinds of tasks?

Perform them multiple times. Find idea blogs (etc) online like Rosetta Code and Project Euler.

1

u/malicart Nov 19 '19

Perform them multiple times.

This is the ticket, keep reading and writing code until you see non-sense, keep going till it makes sense. Think logically and break problems into small parts.