Site icon crypticknwoledge.com

PHP- Types of Operators

PHP has a variety of operators that can be used in different types of expressions. Here are some examples of common operators in PHP:

Arithmetic operators

Arithmetic operators are used to perform basic arithmetic operations on numerical values.

$x = 10;
$y = 5;

echo $x + $y; // 15
echo $x - $y; // 5
echo $x * $y; // 50
echo $x / $y; // 2
echo $x % $y; // 0

Assignment operators

Assignment operators are used to assign a value to a variable.

$x = 10;
$y = 5;

$x += $y; // $x is now 15
$x -= $y; // $x is now 10
$x *= $y; // $x is now 50
$x /= $y; // $x is now 10
$x %= $y; // $x is now 0

Comparison operators

Comparison operators are used to compare two values and return a Boolean result.

$x = 10;
$y = 5;

echo $x == $y; // false
echo $x != $y; // true
echo $x > $y; // true
echo $x < $y; // false
echo $x >= $y; // true
echo $x <= $y; // false

Logical operators

Logical operators are used to perform logical operations on Boolean values.

$x = true;
$y = false;

echo $x && $y; // false
echo $x || $y; // true
echo !$x; // false

These are just a few examples of the operators available in PHP. There are many other operators that can be used for different purposes, such as the ternary operator (? :) for conditional expressions, the bitwise operators for working with binary data, and the type operators for checking the type of a value.

Exit mobile version