In the previous tutorial, you learned how to store data using PHP Variables. Now it’s time to learn how to actually do something with that data. This is where PHP Operators come in — they allow you to perform calculations, comparisons, and logical decisions inside your scripts.
This is Tutorial 3 of 10 in our PHP Basics for Beginners series. In this tutorial, you will explore the main categories of PHP Operators and see practical examples of each one in action.
What are PHP Operators?
PHP Operators are special symbols or keywords used to perform operations on variables and values. For example, when you add two numbers together or check whether one value is greater than another, you are using PHP Operators. Without them, your PHP Variables would just sit there holding data with no way to interact with each other.
PHP supports several categories of operators, and understanding each one is essential before moving on to control structures and loops later in this series.
Arithmetic Operators
Arithmetic PHP Operators are used to perform basic mathematical calculations such as addition, subtraction, multiplication, and division. These are likely the first operators you will use in almost every PHP script you write.
<?php
$a = 10;
$b = 3;
echo $a + $b;
echo $a - $b;
echo $a * $b;
echo $a / $b;
echo $a % $b;
?>
The modulus operator (%) deserves special attention among arithmetic PHP Operators. It returns the remainder after division, which is extremely useful for tasks like checking if a number is even or odd.
Assignment Operators
Assignment PHP Operators are used to assign values to variables. The most basic one is the equals sign, but PHP also provides shorthand assignment operators that combine arithmetic with assignment in a single step.
<?php
$total = 50;
$total += 10;
$total -= 5;
$total *= 2;
$total /= 3;
echo $total;
?>
Using these shorthand assignment PHP Operators makes your code shorter and easier to read once you get comfortable with the syntax, instead of writing out the full expression every time.
Comparison Operators
Comparison PHP Operators are used to compare two values and return either true or false. These operators become extremely important once you start working with conditional logic in the next tutorial.
<?php
$x = 10;
$y = "10";
var_dump($x == $y);
var_dump($x === $y);
var_dump($x != $y);
var_dump($x > 5);
var_dump($x <= 10);
?>
Pay close attention to the difference between == and === in comparison PHP Operators. The double equals checks only the value, while the triple equals checks both the value and the data type, which prevents unexpected bugs in larger applications.
Logical Operators
Logical PHP Operators allow you to combine multiple conditions together. These are commonly used alongside comparison operators when you need to check more than one condition at the same time.
| Operator | Name | Description |
|---|---|---|
| && | AND | True if both conditions are true |
| || | OR | True if at least one condition is true |
| ! | NOT | Reverses the result of a condition |
<?php
$age = 20;
$hasID = true;
var_dump($age >= 18 && $hasID);
var_dump($age < 18 || $hasID);
?>
Logical PHP Operators become extremely powerful once combined with if statements, which you will learn about in the very next tutorial of this series.
Increment and Decrement Operators
PHP also provides shorthand PHP Operators for increasing or decreasing a variable’s value by one. These are frequently used inside loops, which you will encounter later in this series.
<?php
$count = 5;
$count++;
echo $count;
$count--;
echo $count;
?>
The Ternary Operator
Among the more interesting PHP Operators is the ternary operator, which offers a shorthand way to write simple if-else logic in a single line. It follows the pattern: condition, question mark, value if true, colon, value if false.
<?php
$age = 20;
$status = ($age >= 18) ? "Adult" : "Minor";
echo $status;
?>
The ternary operator is one of the most practical PHP Operators once you start writing cleaner, more compact conditional code. For a complete reference of every operator PHP supports, check the official PHP operators documentation.
What’s Next?
You now understand how PHP Operators work across arithmetic, assignment, comparison, logical, and ternary categories. In the next tutorial, we will use these very operators to build real conditional logic with if/else statements and switch cases.
If you missed the previous lesson, check out Tutorial 2: PHP Variables Guide, or explore all lessons in our PHP category.
Practice Exercise
Complete the following tasks to reinforce what you learned in this tutorial:
- Create a PHP file named
operators-practice.php - Declare two integer variables and perform all five arithmetic operations on them
- Use the modulus operator to check whether a given number is even or odd, and echo the result as text
- Declare a variable with value 15, then use three different assignment operators to modify it step by step
- Compare two variables using both == and === and echo the boolean result of each using var_dump()
- Write a logical operator expression that checks if a person’s age is between 18 and 60
- Use the ternary operator to check if a number is positive or negative and echo the result
Bonus Challenge: Write a script using the increment operator inside a repeated echo statement (without using a loop) to print the numbers 1 through 5, incrementing a single variable each time.

