EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

PHP Operators

Home » Software Development » Software Development Tutorials » PHP Tutorial » PHP Operators

PHP-Operators

Introduction to PHP Operators

Operators are symbols that are used to perform the mathematical calculations like addition, subtraction, multiplication. PHP supports various operators to perform not only simple mathematical operations but also to perform some logical operation like AND, OR, NOT, comparison operations like greater than, less than and many more. Operators are nothing that takes one or more value and yields another one value.

Top 6 Types of PHP Operators

The different operators used in PHP is as follows:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1. Arithmetic PHP Operators

Like every programming language, PHP also supports Arithmetic operators which are used to perform simple arithmetical operations, such as addition, subtraction, division, multiplication, etc.

i) Addition Operator( + ): This operator is used to add two Values. Suppose X and Y are two Values, this plus operators will add up these two Values X + Y.

Syntax:

$x + $y

ii) Subtraction Operator( – ): This operator is used to subtracting two Values. Suppose X and Y are two Values, then this minus operator will subtract the value of the second Value from the first Value.

Syntax:

$x - $y

iii) Multiplication Operator( * ): This operator is used to multiply two Values. Suppose X and Y are two Values then this multiplication operator will multiply X with Y.

Syntax:

$x * $y

iv) Division Operator( / ): This operator is used to numerator by the denominator. Suppose X and Y are two Values, this division operator divides the numerator by denominator.

Popular Course in this category
PHP Training (5 Courses, 3 Project)5 Online Courses | 3 Hands-on Project | 28+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,726 ratings)
Course Price

View Course

Related Courses
Java Servlet Training (6 Courses, 12 Projects)All in One Software Development Bundle (600+ Courses, 50+ projects)

Syntax:

$x / $y

v) Modulus Operator( % ): This operator is used to give the remainder of the division. Suppose X and Y are two Values then this modulus operator first divides the numerator by denominator and gives the remainder.

Syntax:

$x % $y

vi) Exponentiation( ** ): This operator is used to raise one quantity to the power of another value. Suppose X and Y are two Values, then this exponentiation operator raises the value of X to the power Y.

Syntax:

$x ** $y

2. Assignment PHP Operators

Assignment operators are used with numeric values to assign a value to a variable. In PHP, = is the basic assignment operator which means that the left Value gets set to the value of the assignment expression on the right. Below is the list of Assignment operators used in PHP

  • Simple Assignment Operator( = ): This operator Assigns values from the right Values to the left Value.
  • Add AND Operator( += ): This operator adds the right Value to the left Value and assign the output to the left Value.
  • Subtract AND Operator( -= ): This operator subtracts the right Value from the left Value and assigns the result to the left Value.
  • Multiply AND Operator( *= ): This operator multiplies the right Value with the left Value and assigns the result to the left Value.
  • Divide AND Operator( /= ): This operator divides the left Value with the right Value and assigns the result to the left Value.
  • Modulus AND Operator( %= ): This operator takes modulus using two Values and assigns the result to the left Value.

3. Comparison of PHP Operators

The PHP comparison operators are used to compare two values Those values can be number or string.

i) Equal to( == ): This operator returns True if both the operands are equal.

Syntax:

$x == $y

ii) Identical( === ): This operator returns True if both the operands are equal and are of the same type.

Syntax:

$x === $y

iii) Not Identical( !== ): This operator returns True if both the operands are not equal and are of different types.

Syntax:

$x !== $y

iv) Not Equal( <> ): This operator returns True if both the operands are unequal.

Syntax:

$x <> $y

v) Not Equal( != ): This operator returns True if both the operands are unequal.

Syntax:

$x != $y

vi) Less Than( < ): This operator returns True if $x is less than $y.

Syntax:

$x < $y

vii) Greater Than( > ): This operator returns True if $x is greater than $y.

Syntax:

$x > $y

viii) Less Than or Equal To( <= ): This operator returns True if $x is less than or equal to $y.

Syntax:

$x <= $y

ix) Greater Than or Equal To( >= ):  This operator returns True if $x is greater than or equal to $y.

Syntax:

$x >= $y

4. Increment/Decrement PHP Operators

These are called the unary operators as it operates on single operands. These operators are used to increment or decrement values.

i) Pre-Increment( ++ ): This operator initially increments $x by one, then return $x.

Syntax:

++$x

ii) Pre-Decrement( — ): This operator initially decrements $x by one, then return $x.

Syntax:

--$x

iii) Post-Increment( ++ ): This operator First returns $x, then increments it by one.

Syntax:

$x++

iv) Pre-Decrement( — ): This operator first returns $x, then decrement it by one.

Syntax:

$x—

5. String PHP Operators

String Operators are implemented over strings.

i) Concatenation( . ): This operator Concatenates Two strings.

Syntax:

$text1.$text2

ii) Concatenation and assignment( .= ): This operator Appends two strings.

Syntax:

$text1.$text2

6. Logical PHP Operators

Logical operators are used to combining conditional statements.

i) AND: This operator returns true if both the operands are true else returns false.

Syntax:

$x and $y

ii) OR: This operator returns true if either of the operands is true else returns false.

Syntax:

$x or $y

iii) XOR: This operator returns true if either of the operands is true and if both are true then I will return false.

Syntax:

$x xor $y

iv) &&: This operator returns true if both the operands are true else returns false.

Syntax:

$x && $y

v) NOT: This operator returns True if $x is false.

Syntax:

!$x

Conclusion

It play an important role in PHP when it comes to mathematical calculations. It also supports various operators like logical operators, string operators, etc.

Recommended Articles

This is a guide to PHP Operators. Here we discuss the top 6 types of PHP Operators i.e. Arithmetic, Assignment, Comparison, Increment/Decrement, Logical, String in detail manner. You may also look at the following articles to learn more –

  1. PHP Superglobal Variables
  2. PHP String Operators
  3. Bitwise Operators in PHP
  4. Logical Operators in PHP

PHP Training (5 Courses, 3 Project)

5 Online Courses

3 Hands-on Project

28+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PHP Tutorial
  • Operators
    • PHP Operators
    • Arithmetic Operators in PHP
    • Comparison Operators in PHP
    • Logical Operators in PHP
    • Bitwise Operators in PHP
    • Ternary Operator in PHP
    • PHP String Operators
  • PHP Basic
    • Introduction To PHP
    • What is PHP
    • PHP Keywords
    • Advantages of PHP
    • Career In PHP
    • Comments in PHP
    • PHP Commands
    • PHP Frameworks
    • PHP Compiler
    • Variables in PHP
    • PHP Superglobal Variables
    • PHP Versions
    • Object in PHP
    • What is Drupal
    • Top PHP Frameworks
    • WebStorm IDE
    • What is phpMyAdmin?
    • PhpStorm
    • Install phpMyAdmin
    • Phalcon Model
  • Data Types
    • PHP Data Types
    • PHP Integer
    • PHP Booleans
  • Control Statements
    • Control Statement in PHP
    • PHP if Statement
    • if else Statement in PHP
    • elseif in PHP
    • PHP Switch Statement
    • Continue in PHP
    • Break in PHP
  • Loops
    • PHP Loops
    • For Loop in PHP
    • PHP Do While Loop
    • PHP While Loop
    • While Loop in PHP
    • Foreach Loop in PHP
  • Constructor
    • Constructor in PHP
    • Destructor in PHP
  • State Management
    • Cookie in PHP
    • Sessions in PHP
  • Array
    • What is PHP Array
    • Arrays in PHP
    • 2D Arrays in PHP
    • Associative Array in PHP 
    • Multidimensional Array in PHP
    • Indexed Array in PHP
    • PHP Array Functions
    • PHP unset Array
    • PHP Append Array
    • PHP Array Search
    • PHP Split Array
    • PHP array_push()
    • PHP array_pop()
  • Functions
    • Functions in PHP
    • PHP Math Functions
    • PHP Recursive Function
    • PHP String Functions
    • Hashing Function in PHP
    • Date Function in PHP
    • PHP Anonymous Function
    • Calendar in PHP
    • PHP Call Function
    • PHP Pass by Reference
    • PHP ucfirst()
    • PHP ucwords()
    • trim() in PHP
    • isset() Function in PHP
    • PHP replace
    • PHP fpm
    • PHP strpos
    • preg_match in PHP
    • PHP preg_replace()
    • PHP ob_start()
    • PHP Reflection
    • PHP Split String
    • PHP URL
    • PHP preg_match_all
    • PHP strtoupper()
    • PHP preg_split()
    • PHP substr_replace()
    • PHP setlocale()
    • PHP substr_count()
    • PHP Serialize
    • PHP strlen()
    • PHP async
    • PHP Date Time Functions
    • PHP timezone
    • PHP Data Object
    • print_r() in PHP
    • PHP header()
    • PHP strip_tags()
    • PHP chop()
    • PHP MD5()
    • PHP unset()
    • PHP crypt()
    • PHP wordwrap()
    • PHP is_null()
    • PHP strtok()
    • PHP bin2hex()
    • PHP parse_str()
    • PHP levenshtein()
    • PHP addslashes()
    • PHP strtotime
    • PHP sha1()
    • PHP explode()
    • PHP sscanf()
    • PHP require_once
    • PHP Zip Files
    • PHP $_SERVER
    • PHP $_POST
    • PHP Include and Require
    • PHP POST Method
  • Advanced
    • Overloading in PHP
    • Overriding in PHP
    • Method Overloading in PHP
    • Inheritance in PHP
    • Multiple Inheritance in PHP
    • PHP Interface
    • Encapsulation in PHP
    • PHP Constants
    • PHP Magic Constants
    • PHP Regular Expressions
    • PHP GET Method
    • PHP Annotations
    • PHP Encryption
    • PHP file Functions
    • PHP readfile
    • PHP?Write File
    • PHP Append File
    • PHP Type Hinting
    • PHP Filters
    • PHP Float
    • PHP Form
    • PHP Form Validation
    • Sorting in PHP
    • PHP usort()
    • PHP Stack Trace
    • PHP Stack Overflow
    • PHP Pagination
    • PHP implode
    • Polymorphism in PHP
    • Abstract Class in PHP
    • PHP Final Class
    • PHP Custom Exception
    • error_reporting() in PHP
    • PHP Log Errors
    • Access Modifiers in PHP
    • PHP Change Date Format
    • Static Method in PHP
    • PHP File Handling
    • PHP Output Buffering
    • Get IP Address in PHP
    • Upload a File in PHP
    • String in PHP
    • Public Function in PHP
    • Private in PHP
    • Protected in PHP
    • basename in PHP
    • Validation in PHP
    • PHP mail()
    • PHP Email Form
    • PHP Directory
    • PHP Create Session
    • PHP include_once
    • PHP json_decode
    • PHP XMLWriter
    • PHP XML Reader
    • PHP XML Parser
    • PHP XML into Array
    • Phalcon Framework
  • Programs
    • Patterns in PHP
    • Star Patterns in PHP
    • Swapping in PHP
    • Fibonacci Series PHP
    • Factorial in PHP
    • Reverse String in PHP
    • Square Root in PHP
    • Random Number Generator in PHP
    • Palindrome in PHP
    • Prime Numbers in PHP
    • Armstrong Number in PHP
    • Socket Programming in PHP
    • Login Page in PHP
    • PHP Login Template
    • PHP Object to String
  • Database
    • PHP Database Connection
    • How to Connect Database to PHP
  • Interview Questions
    • PHP Interview Questions
    • PHP OOP Interview Questions
    • CakePHP Interview Questions
    • Core PHP Interview Questions

Related Courses

PHP Training Course

Java Servlet Training

Software Development Course Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - PHP Training (5 Courses, 3 Project) Learn More