<?php
$score = 42;
echo "Your score is $score";
?>
In this example, the variable `$score
` is assigned the value `42`. When the code is executed.
Your score is 42
<?php
$x = 10;
$y = 5;
$sum = $x + $y;
$diff = $x - $y;
$product = $x * $y;
$quotient = $x / $y;
$remainder = $x % $y;
echo "Sum: $sum\n";
echo "Difference: $diff\n";
echo "Product: $product\n";
echo "Quotient: $quotient\n";
echo "Remainder: $remainder\n";
?>
In this example, we declare two integer variables `$x
` and `$y
`, and then perform arithmetic operations on them.
Sum: 15
Difference: 5
Product: 50
Quotient: 2
Remainder: 0
<?php
$x = 10;
$y = 5;
if ($x > $y) {
echo "$x is greater than $y";
} elseif ($x < $y) {
echo "$x is less than $y";
} else {
echo "$x is equal to $y";
}
?>​
In this example, we use the comparison operators `>
` and `<
` to compare the values of `$x
` and `$y
`.
10 is greater than 5