First steps in PHP

Learning project: PHP

01/2023

In mid-January 2023, I began a program to expand my qualifications. I was excited to get more familiar with programming and the Educom training started with the PHP language. This project is one of my first steps as a developer and I did it at the end of the first week of the training.

What’s the program about?
I wrote 4 different algorithms to draw a triangle formed by asterisks. In addition to the assignment, I implemented the drawing of a diamond formed by asterisks, which is actually a combination of the same algorithm but applied bi-directionally.
After the user enters a number, the program draws the shapes as the number of rows and the number of asterisks on the last row correspond to the entered number.

PHP
Solution 1
<?php for ($i=1; $i<=$aantal_rijen; $i++) { for ($j=1; $j<=$aantal_rijen-$i; $j++) { echo "&nbsp; "; } for ($k=1; $k<=$i-1; $k++) { echo "*"; } for ($p=2; $p<=$i+1; $p++) { echo "*"; } } ?>
Solution 2
<?php for ($i=0; $i<$aantal_rijen; $i++) { for($j=0; $j<$aantal_rijen*2-1; $j++) { if ($j<$aantal_rijen-$i-1 || $j>=$aantal_rijen+$i) { echo "&nbsp; "; } else { echo "*"; } } } ?>
Solution 3
<?php for ($i=0; $i<$aantal_rijen; $i++) { for($j=0; $j<$aantal_rijen-$i-1; $j++) { echo "&nbsp; "; } for($j=0; $j<$i*2+1; $j++) { echo "*"; } } ?>
Solution 4
<?php for ($i=0; $i<$aantal_rijen; $i++) { for($j=0; $j<$aantal_rijen+$i; $j++) { if ($j<$aantal_rijen-$i-1) { echo "&nbsp; "; } else { echo "*"; } } } ?>
Collatz conjecture – PHP
Wink Wink – Dating website