2026-07-23
Misc - Programming Php

Page Title: Misc - Programming Php
Last Modified: 2026-07-01 06:52:23
Current Date: 2026-07-23 15:06:58 UTC

PHP is a server-side scripting language designed for building dynamic web applications and generating HTML.

It process requests on the server, access databases, handle forms, manage sessions, and output HTML/CSS/JS to clients.

These are my Programming Forgets.
Due to the medication I take I do struggle at times to remember or differentiate between programming languages formats and their language comprehensions so I just place these simple steps here as code examples to help me remember.

If you copy any of these examples remember a PHP script needs to start with <?php and end with a ?> when running the script on the server.

These are my Programming Forgets

Due to the medication I take I do struggle at times to remember or differentiate between programming languages formats and their language comprehensions so I just place these simple steps here as code examples to help me remember.

PHP Conditions and If Else statements
PHP supports the usual logical conditions from mathematics:
Equals: a == b
Not Equals: a != b
Less than: a < b
Less than or equal to: a <= b
Greater than: a > b
Greater than or equal to: a >= b
These conditions can be used in several ways, most commonly in "if statements" and loops.
					
$a = 200;
$b = 33;

if ($b > $a) {
    echo "b is greater than a";
} elseif ($a == $b) {
    echo "a and b are equal";
} else {
    echo "a is greater than b";
}
					
PHP For Next Loop
A for next loop is used for iterating over a sequence.
With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
Here is a simple for-next which will print 0 to 5 as the loop starts at 0 and finishes at 5
					
for ($x = 0; $x < 6; $x++) {
    echo $x . PHP_EOL;
}
					

 

PHP For Next Loop with break statement
A for next loop with break statement that 'breaks' the loop when the statement is true, in this case will print 0 to 3 and then break out of the loop
					
for ($x = 0; $x < 6; $x++) {
    echo $x . PHP_EOL;
    if ($x == 3) {
        break;
    }
}
					

 

PHP For Next Loop with continue statement
A for next loop with continue statement that 'continue' the loop when the statement is true, in this case will print 0 to 3 then will print 'Hello, x is 3' and then the loop will continue printing 4 to 5
					
for ($x = 0; $x < 6; $x++) {
    echo $x . PHP_EOL;

    if ($x == 3) {
        echo "Hello, x is $x" . PHP_EOL;
        continue;
    }
}
					

 

php While Loop
A while loop we can execute a set of statements as long as a condition is true.
Here is a simple while which will print 0 to 5 and then exit the loop. The '<' (less than) means process the loop while x is less than 6 but not including 6
					
$x = 0;
while ($x < 6) {
    echo $x . PHP_EOL;
    $x += 1;
}
					

 

php While Loop with break statement
A while loop with break statement that 'breaks' the loop when the statement is true, in this case will print 0 to 3 and then break out of the loop
Here is a simple while which will print 0 to 3 and then exit the loop.
					
$x = 0;
while ($x < 6) {
    echo $x . PHP_EOL;

    if ($x == 3) {
        break;
    }
    $x += 1;
}
					

 

php While Loop with continue statement
A while loop with continue statement will execute a set of statements as long as a condition is true.
in this case will print 1 to 3 then will print 'Hello, x is 3' and then the loop will continue printing 4 to 6
					
$x = 0;
while ($x < 6) {
    $x += 1;
    echo $x . PHP_EOL;

    if ($x == 3) {
        echo "Hello, x is $x" . PHP_EOL;
        continue;
    }
}
					

Copyright © 2002 to 2026