start learning
Image 1
536300100960112

PHP Operators

PHP operators are symbols or keywords that perform operations on variables and values. They allow you to manipulate and work with data in your PHP scripts.

Here's a definition, example, and clarification for some common PHP operators:


Arithmetic Operators

Arithmetic operators perform basic mathematical operations.


$a = 10;
$b = 5;
$sum = $a + $b; // Addition
$difference = $a - $b; // Subtraction
$product = $a * $b; // Multiplication
$quotient = $a / $b; // Division
$remainder = $a % $b; // Modulus
 


Assignment Operators

Assignment operators assign values to variables.


$x = 5; // Assignment
$y += 3; // Addition assignment ($y = $y + 3)
$z -= 2; // Subtraction assignment ($z = $z - 2)
 


Comparison Operators

Comparison operators compare two values and return a Boolean (true or false) result.


$a = 10;
$b = 5;
$isEqual = ($a == $b); // Equal
$isNotEqual = ($a != $b); // Not equal
$isGreaterThan = ($a > $b); // Greater than
$isLessThan = ($a < $b); // Less than
 


Logical Operators

Logical operators perform logical operations on Boolean values.


$isTrue = true;
$isFalse = false;
$andResult = ($isTrue && $isFalse); // Logical AND
$orResult = ($isTrue || $isFalse); // Logical OR
$notResult = !$isTrue; // Logical NOT
 


String Concatenation Operator

The dot . operator is used to concatenate (join) strings.


$firstName = "John";
$lastName = "Doe";
$fullName = $firstName . " " . $lastName;
 


These are some of the fundamental PHP operators. Understanding and using these operators effectively is essential for performing various operations and calculations in PHP scripts.


×