Resource - https://www.w3schools.com/php/
<?php
..code in here
?>
These tags can be used to indicate the start and stop of PHP multiple times in one document, which is useful when programming large pages using HTML
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
$cars = array("Volvo","BMW","Toyota");
echo $x
?>
When out putting variables you do not use quotes.
<?php
echo "My first PHP script!";
?>
OR
echo ('My first page')
You can echo html tags and elements in the same quotes
echo "<h2>PHP is Fun!</h2>";
If you would like to concatenate variables and other data types with strings, you join them with the . command
<?php
$age = 10
$name = "John"
echo $name . " is " . $age." years old."
?>
+ Addition $x + $y
- Subtraction $x - $y
* Multiplication $x * $y
/ Division $x / $y
% Modulus $x % $y
** Exponentiation $x ** $y - Result of raising $x to the $y'th power (Introduced in PHP 5.6)
if (condition) {
code to be executed if condition is true;
}
<?php
$t = 10;
if ($t < 20) {
echo "Have a good day!";
}
?>
if (condition) {
code to be executed if condition is true;
} else {
code to be executed if condition is false;
}
<?php
$t = 50;
if ($t < 20) {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
for (init counter; test counter; increment counter) {
code to be executed;
}
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
foreach ($array as $value) {
code to be executed;
}
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
function functionName() {
code to be executed;
}
<?php
function writeMsg() {
echo "Hello world!";
}
writeMsg(); // call the function
?>
<?php
function familyName($fname, $year) {
echo "$fname Refsnes. Born in $year <br>";
}
familyName("Hege", "1975");
familyName("Stale", "1978");
familyName("Kai Jim", "1983");
?>
Create an empty array
$cars =[];
$cars =['Holden','Ford'];
Length or Count of Array:
$length = count($cars)
Add values to array - array_name, value
push_array($cars,"Holden");
Remove / Splice elements from array (array,index,qty)
splice_array($cars,2,1);
str_replace(find,replace,string,count)
header('location:index.php');