Operators are used to perform operations on variables and values. PHP supports various types of operators.
Arithmetic operators are used to perform mathematical operations:
<?php
$x = 10;
$y = 5;
echo $x + $y; // Addition
echo $x - $y; // Subtraction
echo $x * $y; // Multiplication
echo $x / $y; // Division
?>
Comparison operators are used to compare values:
<?php
$x = 10;
$y = 5;
echo $x == $y; // Equal to
echo $x != $y; // Not equal to
echo $x > $y; // Greater than
?>
Write a PHP script that uses both arithmetic and comparison operators to calculate and compare two numbers.
==
and !=
?Answers: