Documente Academic
Documente Profesional
Documente Cultură
$sum_total = $second_number-$first_number;
<?php
$first_number = 10;
$second_number = 20;
$third_number = 100;
$sum_total = $third_number -
$second_number - $first_number;
echo($sum_total);
?>
To multiply in PHP (and just about every other
programming language), the * symbol is used.
If you see 20 * 10, it means multiply 20 by 10.
$add = $a + $b +$c;
$sub = $c - $a;
$mult = $a * $b;
$div = $c / 3;
PHP Assignment Operators
x += y x = x + y Addition
x -= y x=x-y Subtraction
x *= y x = x * y Multiplication
x /= y x=x/y Division
x %= y x = x % y Modulus
$y = 20; $i = 5;
$y += 100; $i *= 6;
echo $y; echo $i;
$z = 50; $j = 10;
$z -= 25; $j /= 5;
echo $z; echo $j;
IF statement
if (<condition>) {
//php code goes here
}
else {
//php code goes here
}
Alternative Syntax
if(<condition>) :
//html code goes here
else :
//html code goes here
endif;
Looping statement are the statements
execute one or more statement repeatedly
several number of times.
Types of Looping statement
while
do, while
for
foreach
The while loop executes a block of code as
long as the specified condition is true.
Syntax:
while(condition){
code to be executed
}
The do, while loop will always execute the
block of code once, it will then check the
condition, and repeat the loop while the
specified condition is true.
Syntax:
do{
code to be executed
}
while(condition);
The for loop is used when you know in
advance how many times the script should
run.
Syntax
for (initial value; condition; counter) {
code to be executed;
}
The foreach loop works only on arrays, and is
used to loop through each key/value pair in
an array.
Syntax
foreach ($array as $value) {
code to be executed;
}