This commit is contained in:
2026-03-06 21:27:16 -05:00
parent 1fdfbb1b4f
commit 41ebd4ac62
21 changed files with 1018 additions and 43 deletions
+64
View File
@@ -0,0 +1,64 @@
<?php
// All of the following will give the same result.
echo 123 + 1;
echo '<br>';
echo "123" + 1;
echo '<br>';
echo "123" + "1";
echo '<br><br>';
// Arithmetic operators.
echo '<strong>Arithmetic operators</strong><br>';
echo 'Addition (+) ' . 1 + 2 . '<br>';
echo 'Subtraction (-) ' . 2 - 1 . '<br>';
echo 'Multiplication (*) ' . 2 * 2 . '<br>';
echo 'Division (/) ' . 4 / 2 . '<br>';
echo 'Modulus (%) ' . 4 % 2 . '<br>';
$a = 1;
$a++;
echo 'Increment (++) ' . $a . '<br>';
$a--;
echo 'Decrement (--) ' . $a . '<br>';
echo '<br>';
// Assignment operators.
echo '<strong>Assignment operators</strong><br>';
$a = 2;
echo $a . '<br>';
$a += 2;
echo $a . '<br>';
$a -= 2;
echo $a . '<br>';
$a *= 2;
echo $a . '<br>';
$a /= 2;
echo $a . '<br>';
echo '<br>';
// Comparison operators.
echo '<strong>Comparison operators</strong><br>';
$a = 1;
$b = 2;
$c = '2';
echo ($a < $b) . '<br>';
echo ($a > $b) . '<br>';
echo ($a == $b) . '<br>';
echo ($a != $b) . '<br>';
echo ($b == $c) . '<br>';
echo ($b === $c) . '<br>';
echo '<br>';
// Formatting numbers.
echo '<strong>Formatting numbers</strong><br>';
echo 'Round (2.49): ' . round(2.49) . '<br>';
echo 'Number Format (21233122):' . number_format(21233122) . '<br>';
echo 'Printf: ';
$sub = 5;
$tax = 0.65;
printf('The subtotal is %u, making the tax
%.2f.', $sub, $tax);
echo '<br>';
echo 'Mt Rand: ' . mt_rand(0, 100);