Free cookie consent management tool by TermsFeed Generator PHP Operators | Amir Kamizi
AMIR KAMIZI
Home Blog Courses Books Newsletter Store Membership Buy me a coffee
PHP Operators

PHP Operators

Last Updated on Mar 21, 2023

What are we going to do?

Today's lesson is very short and rather than explaining everything I will show you an example of each operation. so let's get started.

Arithmetic Operators

Addition +

echo 2 + 4;
// 6

Subtraction -

echo 4 - 2;
// 2

Multiplication *

echo 2 * 2;
// 4

Division /

echo 4 / 2;
// 2

Modulus % (Remainder of $x divided by $y)

echo 9 % 2;
// 1

Exponentiation ** ($x to the power of $y)

echo 2 ** 3;
// 8

Comparison Operators

Equal ==

2==2  
// true

2=='2' 
// true

Identical === (equal and have the same type)

2===2 
// true

2==='2'
// false

Not equal !=

2!=2  
// false

2!='2'  
// false

Not identical !==

2!==2  
// false

2!=='2' 
// true

Greater than >

2 > 4   
// false

Less than <

2 < 4   
// true

Greater than or equal to >=

2 >= 2   
// true

Less than or equal to <=

2 <= 3   
// true

Logic Operators

All the comparison operators can be considered as logic operators as well. plus the following operators

AND &&

True && false   
// false

Or ||

True || false   
// true

Xor (True if either $x or $y is true, but not both)

True xor true    
// false

True xor false    
// true

Not !

!true    
// false

https://youtu.be/Y-mCSJrXs3Y

Conclusion

Now you know about arithmetic operators, comparison operators and logic operators in PHP.

I recommend you to open a PHP file and try every one of them. calculate different values. combine them and see which one is calculated first. compare the values. use the logic operatros. the better you understand them the better you can apply that knowledge in your career.

If you have any suggestions, questions, or opinions, please contact me. I’m looking forward to hearing from you!

Key takeaways

  • what are arithmetic operators in php
  • what are comparison operatros in php
  • what are logic operators in php
  • examples about all of them

Category: programming

Tags: #php

Join the Newsletter

Subscribe to get my latest content by email.

I won't send you spam. Unsubscribe at any time.

Related Posts

the ultimate guide to Git: learn everything you need in less than 1 hour
Nov 28, 2022 programming

the ultimate guide to Git: learn everything you need in less than 1 hour

Here is everything you need to know about git in a series of short question and answers. ...

11 Min Read Read More
How to Split an Excel File into Multiple Files Using PHP
May 07, 2024 programming

How to Split an Excel File into Multiple Files Using PHP

Sometimes you might have an excel files that you need to split. splitting the file into multiple files with PHP can be easily done. ...

9 Min Read Read More
How to Combine Excel Files Using Python
May 08, 2024 programming

How to Combine Excel Files Using Python

Sometimes you might have many excel files that you need to combine, whether it's reports, user data or anything else, merging them into one file with Python can be easily done. ...

9 Min Read Read More
TypeScript Beginner to Advanced 2025: The Complete Guide
Jul 18, 2025 programming

TypeScript Beginner to Advanced 2025: The Complete Guide

TypeScript is no longer optional for serious JavaScript developers, it’s essential. Whether you're building modern front-end applications with React, scaling backend services with Node.js, or contributing to large open-source projects, TypeScript is the industry standard in 2025. ...

23 Min Read Read More

Recommended Courses

Introduction to Machine Learning in PHP

Introduction to Machine Learning in PHP

Learn to Build Different Machine Learning Models Easily ...

PHP Tutorial Beginner to Advanced

PHP Tutorial Beginner to Advanced

Learn everything you need to start a successful career as a PHP developer ...