PHP Conditional Statements

PHP - The if Statement

			<?PHP
					echo date_default_timezone_get(). "<br>";
					date_default_timezone_set("America/Chicago");
					echo "Current date and time: " . date("Y-m-d H:i:s") . "<br>";

					$t = date("H");

					if ($t < "20") {
   					 echo "Have a good day!";
					}
			?>
		

PHP - The if...else Statement

			<?php
				$t = date("H");

				if ($t < "20") {
  				echo "Have a good day!";
				} else {
  				echo "Have a good night!";
				}
			?>
		

PHP - The if...elseif...else Statement

			<?php
				$t = date("H");

				if ($t < "10") {
 					 echo "Have a good morning!";
				} elseif ($t < "20") {
  					 echo "Have a good day!";
				} else {
  					 echo "Have a good night!";
				}
			?>
		

PHP - The switch Statement

PHP Loops

PHP while Loops

			<?php
				$x = 1;

				while($x <= 5) {
   				 echo "The number is: $x <br>";
    			 	 $x++;
				}
			?>
		

PHP do...while Loop

			<?php
				$x = 1;

				do {
  				echo "The number is: $x <br>";
  				$x++;
				} while ($x <= 5);
			?>
		

PHP for Loops

			<?php
					for ($x = 0; $x <= 10; $x++) {
  						echo "The number is: $x <br>";
					}
			?>
		

PHP foreach Loop

			<?php
					$colors = ["red", "green", "blue", "yellow"];

					foreach ($colors as $value) {
    						echo "$value <br>";
					}
			?>
		

Reference