PHP Operators
Use this lesson when you want to understand the key concepts behind PHP Operators.
Operators are used to perform operations on variables and values. PHP divides operators into several groups.
The PHP arithmetic operators are used with numeric values to perform common arithmetical operations.
+ (Addition)- (Subtraction)* (Multiplication)/ (Division)% (Modulus - Returns remainder)** (Exponentiation)The basic assignment operator in PHP is =. It means that the left operand gets set to the value of the assignment expression on the right.
x = y (Assign)x += y (Addition)x -= y (Subtraction)Comparison operators are used to compare two values (number or string):
== (Equal) - Returns true if values are equal.=== (Identical) - Returns true if values are equal AND they are of the same type.!= (Not equal)> (Greater than)< (Less than)<?php $x = 100; $y = "100";var_dump($x == $y); // returns true because values are equal echo "\n"; var_dump($x === $y); // returns false because types are not equal ?>
Logical operators are used to combine conditional statements: && (And), || (Or), ! (Not).