PHP
Variables:
$x=5;
$word="hello";
Printing:
echo "This is a sentence";
print "The value is $x";
Comparison Operators:
== (equals)
!= (not equals)
> (greater than)
< (less than)
>= (greater than or equal to)
<= (less than or equal to)
echo "Conditional statements:
";
if($x > 5) {
print "$x is greater than 5";
}
if($word == "hello") {
print "The word is hello";
}
else {
print "The word is not hello";
}
echo "For loops:
";
for($i=starting number; $i<=ending number; $i++) {
//Everything between these braces is repeated
}
//start at 0; end at 30; add 1 to $i each time
for($i=0; $i<=30; $i++) {
echo "i is currently $i";
}
//start at 1; end at 19; add 5 to $i each time
for($i=1; $i<20; $i=$i+5) {
echo "i is currently $i";
}
Declaring Functions:
function subtract($x, $y) {
$value = $x-$y;
return $value;
}
function print_hello() {
echo "Hello World";
}
Using Functions:
$result=$subtract(10,5);
echo "$result
";
print_hello();