• Language Reference

Assignment Operators

The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". Don't. It really means that the left operand gets set to the value of the expression on the right (that is, "gets set to").

The value of an assignment expression is the value assigned. That is, the value of " $a = 3 " is 3. This allows you to do some tricky things: <?php $a = ( $b = 4 ) + 5 ; // $a is equal to 9 now, and $b has been set to 4. ?>

In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic , array union and string operators that allow you to use a value in an expression and then set its value to the result of that expression. For example: <?php $a = 3 ; $a += 5 ; // sets $a to 8, as if we had said: $a = $a + 5; $b = "Hello " ; $b .= "There!" ; // sets $b to "Hello There!", just like $b = $b . "There!"; ?>

Note that the assignment copies the original variable to the new one (assignment by value), so changes to one will not affect the other. This may also have relevance if you need to copy something like a large array inside a tight loop.

An exception to the usual assignment by value behaviour within PHP occurs with object s, which are assigned by reference. Objects may be explicitly copied via the clone keyword.

Assignment by Reference

Assignment by reference is also supported, using the " $var = &$othervar; " syntax. Assignment by reference means that both variables end up pointing at the same data, and nothing is copied anywhere.

Example #1 Assigning by reference

The new operator returns a reference automatically, as such assigning the result of new by reference is an error.

The above example will output:

More information on references and their potential uses can be found in the References Explained section of the manual.

Arithmetic Assignment Operators

Bitwise assignment operators, other assignment operators.

  • arithmetic operators
  • bitwise operators
  • null coalescing operator

User Contributed Notes 4 notes

To Top

PHP Tutorial

Php advanced, mysql database, php examples, php reference, php operators.

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
  • Conditional assignment operators

PHP Arithmetic Operators

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

PHP Assignment Operators

The PHP assignment operators are used with numeric values to write a value to a variable.

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.

Advertisement

PHP Comparison Operators

The PHP comparison operators are used to compare two values (number or string):

PHP Increment / Decrement Operators

The PHP increment operators are used to increment a variable's value.

The PHP decrement operators are used to decrement a variable's value.

PHP Logical Operators

The PHP logical operators are used to combine conditional statements.

PHP String Operators

PHP has two operators that are specially designed for strings.

PHP Array Operators

The PHP array operators are used to compare arrays.

PHP Conditional Assignment Operators

The PHP conditional assignment operators are used to set a value depending on conditions:

PHP Exercises

Test yourself with exercises.

Multiply 10 with 5 , and output the result.

Start the Exercise

Get Certified

COLOR PICKER

colorpicker

Report Error

If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:

[email protected]

Top Tutorials

Top references, top examples, get certified.

PHP Assignment Operators

Php tutorial index.

PHP assignment operators applied to assign the result of an expression to a variable. = is a fundamental assignment operator in PHP. It means that the left operand gets set to the value of the assignment expression on the right.

  • TutorialKart
  • SAP Tutorials
  • Salesforce Admin
  • Salesforce Developer
  • Visualforce
  • Informatica
  • Kafka Tutorial
  • Spark Tutorial
  • Tomcat Tutorial
  • Python Tkinter

Programming

  • Bash Script
  • Julia Tutorial
  • CouchDB Tutorial
  • MongoDB Tutorial
  • PostgreSQL Tutorial
  • Android Compose
  • Flutter Tutorial
  • Kotlin Android

Web & Server

  • Selenium Java
  • PHP Tutorial
  • PHP Install
  • PHP Hello World
  • Check if variable is set
  • Convert string to int
  • Convert string to float
  • Convert string to boolean
  • Convert int to string
  • Convert int to float
  • Get type of variable
  • Subtraction
  • Multiplication
  • Exponentiation
  • Simple Assignment
  • Addition Assignment
  • Subtraction Assignment
  • ADVERTISEMENT
  • Multiplication Assignment
  • Division Assignment
  • Modulus Assignment
  • PHP Comments
  • Python If AND
  • Python If OR
  • Python If NOT
  • Do-While Loop
  • Nested foreach
  • echo() vs print()
  • printf() vs sprintf()
  • PHP Strings
  • Create a string
  • Create empty string
  • Compare strings
  • Count number of words in string
  • Get ASCII value of a character
  • Iterate over characters of a string
  • Iterate over words of a string
  • Print string to console
  • String length
  • Substring of a string
  • Check if string is empty
  • Check if strings are equal
  • Check if strings are equal ignoring case
  • Check if string contains specified substring
  • Check if string starts with specific substring
  • Check if string ends with specific substring
  • Check if string starts with specific character
  • Check if string starts with http
  • Check if string starts with a number
  • Check if string starts with an uppercase
  • Check if string starts with a lowercase
  • Check if string ends with a punctuation
  • Check if string ends with forward slash (/) character
  • Check if string contains number(s)
  • Check if string contains only alphabets
  • Check if string contains only numeric digits
  • Check if string contains only lowercase
  • Check if string contains only uppercase
  • Check if string value is a valid number
  • Check if string is a float value
  • Append a string with suffix string
  • Prepend a string with prefix string
  • Concatenate strings
  • Concatenate string and number
  • Insert character at specific index in string
  • Insert substring at specific index in string
  • Repeat string for N times
  • Replace substring
  • Replace first occurrence
  • Replace last occurrence
  • Trim spaces from edges of string
  • Trim specific characters from edges of the string
  • Split string
  • Split string into words
  • Split string by comma
  • Split string by single space
  • Split string by new line
  • Split string by any whitespace character
  • Split string by one or more whitespace characters
  • Split string into substrings of specified length
  • Transformations
  • Reverse a string
  • Convert string to lowercase
  • Convert string to uppercase
  • Join elements of string array with separator string
  • Delete first character of string
  • Delete last character of string
  • Count number of occurrences of substring in a string
  • Count alphabet characters in a string
  • Find index of substring in a string
  • Find index of last occurrence in a string
  • Find all the substrings that match a pattern
  • Check if entire string matches a regular expression
  • Check if string has a match for regular expression
  • Sort array of strings
  • Sort strings in array based on length
  • Foramatting
  • PHP – Format string
  • PHP – Variable inside a string
  • PHP – Parse JSON String
  • Conversions
  • PHP – Convert CSV String into Array
  • PHP – Convert string array to CSV string
  • Introduction to Arrays
  • Indexed arrays
  • Associative arrays
  • Multi-dimensional arrays
  • String array
  • Array length
  • Create Arrays
  • Create indexed array
  • Create associative array
  • Create empty array
  • Check if array is empty
  • Check if specific element is present in array .
  • Check if two arrays are equal
  • Check if any two adjacent values are same
  • Read/Access Operations
  • Access array elements using index
  • Iterate through array using For loop
  • Iterate over key-value pairs using foreach
  • Array foreach()
  • Get first element in array
  • Get last element in array
  • Get keys of array
  • Get index of a key in array
  • Find Operations
  • Count occurrences of specific value in array
  • Find index of value in array
  • Find index of last occurrence of value in array
  • Combine two arrays to create an Associative Array
  • Convert array to string
  • Convert array to CSV string
  • Join array elements
  • Reverse an array
  • Split array into chunks
  • Slice array by index
  • Slice array by key
  • Preserve keys while slicing array
  • Truncate array
  • Remove duplicate values in array
  • Filter elements in array based on a condition
  • Filter positive numbers in array
  • Filter negative numbers in array
  • Remove empty strings in array
  • Delete Operations
  • Delete specific value from array
  • Delete value at specific index in array
  • Remove first value in array
  • Remove last value in array
  • Array - Notice: Undefined offset: 0
  • JSON encode
  • Array Functions
  • array_chunk()
  • array_column()
  • array_combine()
  • array_change_key_case()
  • array_count_values()
  • array_diff_assoc()
  • array_diff_key()
  • array_diff_uassoc()
  • array_diff_ukey()
  • array_diff()
  • array_fill()
  • array_fill_keys()
  • array_flip()
  • array_key_exists()
  • array_keys()
  • array_pop()
  • array_product()
  • array_push()
  • array_rand()
  • array_replace()
  • array_sum()
  • array_values()
  • Create an object or instance
  • Constructor
  • Constants in class
  • Read only properties in class
  • Encapsulation
  • Inheritance
  • Define property and method with same name in class
  • Uncaught Error: Cannot access protected property
  • Nested try catch
  • Multiple catch blocks
  • Catch multiple exceptions in a single catch block
  • Print exception message
  • Throw exception
  • User defined Exception
  • Get current timestamp
  • Get difference between two given dates
  • Find number of days between two given dates
  • Add specific number of days to given date
  • ❯ PHP Tutorial
  • ❯ PHP Operators
  • ❯ Assignment

PHP Assignment Operators

In this tutorial, you shall learn about Assignment Operators in PHP, different Assignment Operators available in PHP, their symbols, and how to use them in PHP programs, with examples.

Assignment Operators

Assignment Operators are used to perform to assign a value or modified value to a variable.

Assignment Operators Table

The following table lists out all the assignment operators in PHP programming.

In the following program, we will take values in variables $x and $y , and perform assignment operations on these values using PHP Assignment Operators.

PHP Program

Assignment Operators in PHP

Assignment Operators Tutorials

The following tutorials cover each of the Assignment Operators in PHP in detail with examples.

  • PHP Simple Assignment
  • PHP Addition Assignment
  • PHP Subtraction Assignment
  • PHP Multiplication Assignment
  • PHP Division Assignment
  • PHP Modulus Assignment

In this PHP Tutorial , we learned about all the Assignment Operators in PHP programming, with examples.

Popular Courses by TutorialKart

App developement, web development, online tools.

PHP Tutorial

  • PHP Tutorial
  • PHP - Introduction
  • PHP - Installation
  • PHP - History
  • PHP - Syntax
  • PHP - Hello World
  • PHP - Comments
  • PHP - Variables
  • PHP - Echo/Print
  • PHP - var_dump
  • PHP - $ and $$ Variables
  • PHP - Constants
  • PHP - Magic Constants
  • PHP - Data Types
  • PHP - Type Casting
  • PHP - Type Juggling
  • PHP - Strings
  • PHP - Boolean
  • PHP - Integers
  • PHP - Files & I/O
  • PHP - Maths Functions
  • PHP - Heredoc & Nowdoc
  • PHP - Compound Types
  • PHP - File Include
  • PHP - Date & Time
  • PHP - Scalar Type Declarations
  • PHP - Return Type Declarations
  • PHP Operators
  • PHP - Operators
  • PHP - Arithmatic Operators
  • PHP - Comparison Operators
  • PHP - Logical Operators
  • PHP - Assignment Operators
  • PHP - String Operators
  • PHP - Array Operators
  • PHP - Conditional Operators
  • PHP - Spread Operator
  • PHP - Null Coalescing Operator
  • PHP - Spaceship Operator
  • PHP Control Statements
  • PHP - Decision Making
  • PHP - If…Else Statement
  • PHP - Switch Statement
  • PHP - For Loop
  • PHP - Foreach Loop
  • PHP - While Loop
  • PHP - Do…While Loop
  • PHP - Break Statement
  • PHP - Continue Statement
  • PHP - Arrays
  • PHP - Indexed Array
  • PHP - Associative Array
  • PHP - Multidimensional Array
  • PHP - Array Functions
  • PHP - Constant Arrays
  • PHP Functions
  • PHP - Functions
  • PHP - Function Parameters
  • PHP - Call by value
  • PHP - Call by Reference
  • PHP - Default Arguments
  • PHP - Named Arguments
  • PHP - Variable Arguments
  • PHP - Returning Values
  • PHP - Passing Functions
  • PHP - Recursive Functions
  • PHP - Type Hints
  • PHP - Variable Scope
  • PHP - Strict Typing
  • PHP - Anonymous Functions
  • PHP - Arrow Functions
  • PHP - Variable Functions
  • PHP - Local Variables
  • PHP - Global Variables
  • PHP Superglobals
  • PHP - Superglobals
  • PHP - $GLOBALS
  • PHP - $_SERVER
  • PHP - $_REQUEST
  • PHP - $_POST
  • PHP - $_GET
  • PHP - $_FILES
  • PHP - $_ENV
  • PHP - $_COOKIE
  • PHP - $_SESSION
  • PHP File Handling
  • PHP - File Handling
  • PHP - Open File
  • PHP - Read File
  • PHP - Write File
  • PHP - File Existence
  • PHP - Download File
  • PHP - Copy File
  • PHP - Append File
  • PHP - Delete File
  • PHP - Handle CSV File
  • PHP - File Permissions
  • PHP - Create Directory
  • PHP - Listing Files
  • Object Oriented PHP
  • PHP - Object Oriented Programming
  • PHP - Classes and Objects
  • PHP - Constructor and Destructor
  • PHP - Access Modifiers
  • PHP - Inheritance
  • PHP - Class Constants
  • PHP - Abstract Classes
  • PHP - Interfaces
  • PHP - Traits
  • PHP - Static Methods
  • PHP - Static Properties
  • PHP - Namespaces
  • PHP - Object Iteration
  • PHP - Encapsulation
  • PHP - Final Keyword
  • PHP - Overloading
  • PHP - Cloning Objects
  • PHP - Anonymous Classes
  • PHP Web Development
  • PHP - Web Concepts
  • PHP - Form Handling
  • PHP - Form Validation
  • PHP - Form Email/URL
  • PHP - Complete Form
  • PHP - File Inclusion
  • PHP - GET & POST
  • PHP - File Uploading
  • PHP - Cookies
  • PHP - Sessions
  • PHP - Session Options
  • PHP - Sending Emails
  • PHP - Sanitize Input
  • PHP - Post-Redirect-Get (PRG)
  • PHP - Flash Messages
  • PHP - AJAX Introduction
  • PHP - AJAX Search
  • PHP - AJAX XML Parser
  • PHP - AJAX Auto Complete Search
  • PHP - AJAX RSS Feed Example
  • PHP - XML Introduction
  • PHP - Simple XML Parser
  • PHP - SAX Parser Example
  • PHP - DOM Parser Example
  • PHP Login Example
  • PHP - Login Example
  • PHP - Facebook and Paypal Integration
  • PHP - Facebook Login
  • PHP - Paypal Integration
  • PHP - MySQL Login
  • PHP Advanced
  • PHP - MySQL
  • PHP.INI File Configuration
  • PHP - Array Destructuring
  • PHP - Coding Standard
  • PHP - Regular Expression
  • PHP - Error Handling
  • PHP - Try…Catch
  • PHP - Bugs Debugging
  • PHP - For C Developers
  • PHP - For PERL Developers
  • PHP - Frameworks
  • PHP - Core PHP vs Frame Works
  • PHP - Design Patterns
  • PHP - Filters
  • PHP - Callbacks
  • PHP - Exceptions
  • PHP - Special Types
  • PHP - Hashing
  • PHP - Encryption
  • PHP - is_null() Function
  • PHP - System Calls
  • PHP - HTTP Authentication
  • PHP - Swapping Variables
  • PHP - Closure::call()
  • PHP - Filtered unserialize()
  • PHP - IntlChar
  • PHP - CSPRNG
  • PHP - Expectations
  • PHP - Use Statement
  • PHP - Integer Division
  • PHP - Deprecated Features
  • PHP - Removed Extensions & SAPIs
  • PHP - FastCGI Process
  • PHP - PDO Extension
  • PHP - Built-In Functions
  • PHP Useful Resources
  • PHP - Questions & Answers
  • PHP - Useful Resources
  • PHP - Discussion
  • Selected Reading
  • UPSC IAS Exams Notes
  • Developer's Best Practices
  • Questions and Answers
  • Effective Resume Writing
  • HR Interview Questions
  • Computer Glossary

PHP - Assignment Operators Examples

You can use assignment operators in PHP to assign values to variables. Assignment operators are shorthand notations to perform arithmetic or other operations while assigning a value to a variable. For instance, the "=" operator assigns the value on the right-hand side to the variable on the left-hand side.

Additionally, there are compound assignment operators like +=, -= , *=, /=, and %= which combine arithmetic operations with assignment. For example, "$x += 5" is a shorthand for "$x = $x + 5", incrementing the value of $x by 5. Assignment operators offer a concise way to update variables based on their current values.

The following table highligts the assignment operators that are supported by PHP −

The following example shows how you can use these assignment operators in PHP −

It will produce the following output −

  • PHP Tutorial
  • PHP Calendar
  • PHP Filesystem
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP IntlChar
  • PHP Image Processing
  • PHP Formatter
  • Web Technology
  • PHP Introduction
  • How to install PHP in windows 10 ?
  • How to Install PHP on Linux?
  • PHP | Basic Syntax
  • How to write comments in PHP ?
  • PHP | Variables
  • PHP echo and print
  • PHP | Data Types
  • PHP | Strings
  • Associative Arrays in PHP
  • Multidimensional arrays in PHP
  • Sorting Arrays in PHP 5

PHP Constants

  • PHP | Constants
  • PHP Constant Class
  • PHP Defining Constants
  • PHP | Magic Constants

PHP Operators

  • PHP | Bitwise Operators
  • PHP | Ternary Operator

PHP Control Statements

  • PHP | Decision Making
  • PHP switch Statement
  • PHP break (Single and Nested Loops)
  • PHP continue Statement
  • PHP | Loops
  • PHP while Loop
  • PHP do-while Loop
  • PHP for Loop
  • PHP | foreach Loop

PHP Functions

  • PHP | Functions
  • PHP Arrow Functions
  • Anonymous recursive function in PHP

PHP Advanced

  • PHP | Superglobals
  • HTTP GET and POST Methods in PHP
  • PHP | Regular Expressions
  • PHP Form Processing
  • PHP Date and Time
  • Describe PHP Include and Require
  • PHP | Basics of File Handling
  • PHP | Uploading File
  • PHP Cookies
  • PHP | Sessions
  • Implementing callback in PHP
  • PHP | Classes
  • PHP | Constructors and Destructors
  • PHP | Access Specifiers
  • Multiple Inheritance in PHP
  • Abstract Classes in PHP
  • PHP | Interface
  • Static Function in PHP
  • PHP | Namespace

MySQL Database

  • PHP | MySQL Database Introduction
  • PHP | MySQL ( Creating Database )
  • PHP Database connection
  • Connect PHP to MySQL
  • PHP | MySQL ( Creating Table )
  • PHP | Inserting into MySQL database
  • PHP | MySQL Select Query
  • PHP | MySQL Delete Query
  • PHP | MySQL WHERE Clause
  • PHP | MySQL UPDATE Query
  • PHP | MySQL LIMIT Clause

Complete References

  • PHP Array Functions
  • PHP String Functions Complete Reference
  • PHP Math Functions Complete Reference
  • PHP Filesystem Functions Complete Reference
  • PHP intl Functions Complete Reference
  • PHP IntlChar Functions Complete Reference
  • PHP Image Processing and GD Functions Complete Reference
  • PHP Imagick Functions Complete Reference
  • PHP ImagickDraw Functions Complete Reference
  • PHP Gmagick Functions Complete Reference
  • PHP GMP Functions Complete Reference
  • PHP Ds\Set Functions Complete Reference
  • PHP Ds\Map Functions Complete Reference
  • PHP Ds\Stack Functions Complete Reference
  • PHP Ds\Queue Functions Complete Reference
  • PHP Ds\PriorityQueue Functions Complete Reference
  • PHP Ds\Deque Functions Complete Reference
  • PHP Ds\Sequence Functions Complete Reference
  • PHP SPL Data structures Complete Reference
  • PHP Ds\Vector Functions Complete Reference
  • PHP DOM Functions Complete Reference

In this article, we will see how to use the operators in PHP, & various available operators along with understanding their implementation through the examples.

Operators are used to performing operations on some values. In other words, we can describe operators as something that takes some values, performs some operation on them, and gives a result. From example, “1 + 2 = 3” in this expression ‘+’ is an operator. It takes two values 1 and 2, performs an addition operation on them to give 3. 

Just like any other programming language, PHP also supports various types of operations like arithmetic operations(addition, subtraction, etc), logical operations(AND, OR etc), Increment/Decrement Operations, etc. Thus, PHP provides us with many operators to perform such operations on various operands or variables, or values. These operators are nothing but symbols needed to perform operations of various types. Given below are the various groups of operators:

  • Arithmetic Operators
  • Logical or Relational Operators
  • Comparison Operators
  • Conditional or Ternary Operators
  • Assignment Operators
  • Spaceship Operators (Introduced in PHP 7)
  • Array Operators
  • Increment/Decrement Operators
  • String Operators

Let us now learn about each of these operators in detail.

Arithmetic Operators: 

The arithmetic operators are used to perform simple mathematical operations like addition, subtraction, multiplication, etc. Below is the list of arithmetic operators along with their syntax and operations in PHP.

Note : The exponentiation has been introduced in PHP 5.6. 

Example : This example explains the arithmetic operator in PHP.

Logical or Relational Operators:

These are basically used to operate with conditional statements and expressions. Conditional statements are based on conditions. Also, a condition can either be met or cannot be met so the result of a conditional statement can either be true or false. Here are the logical operators along with their syntax and operations in PHP.

Example : This example describes the logical & relational operator in PHP.

Comparison Operators: These operators are used to compare two elements and outputs the result in boolean form. Here are the comparison operators along with their syntax and operations in PHP.

Example : This example describes the comparison operator in PHP.

Conditional or Ternary Operators :

These operators are used to compare two values and take either of the results simultaneously, depending on whether the outcome is TRUE or FALSE. These are also used as a shorthand notation for if…else statement that we will read in the article on decision making. 

Here, the condition will either evaluate as true or false. If the condition evaluates to True, then value1 will be assigned to the variable $var otherwise value2 will be assigned to it.

Example : This example describes the Conditional or Ternary operators in PHP.

Assignment Operators: These operators are used to assign values to different variables, with or without mid-operations. Here are the assignment operators along with their syntax and operations, that PHP provides for the operations.

Example : This example describes the assignment operator in PHP.

Array Operators: These operators are used in the case of arrays. Here are the array operators along with their syntax and operations, that PHP provides for the array operation.

Example : This example describes the array operation in PHP.

Increment/Decrement Operators: These are called the unary operators as they work on single operands. These are used to increment or decrement values.

Example : This example describes the Increment/Decrement operators in PHP. 

String Operators: This operator is used for the concatenation of 2 or more strings using the concatenation operator (‘.’). We can also use the concatenating assignment operator (‘.=’) to append the argument on the right side to the argument on the left side.

Example : This example describes the string operator in PHP.

Spaceship Operators :

PHP 7 has introduced a new kind of operator called spaceship operator. The spaceship operator or combined comparison operator is denoted by “<=>“. These operators are used to compare values but instead of returning the boolean results, it returns integer values. If both the operands are equal, it returns 0. If the right operand is greater, it returns -1. If the left operand is greater, it returns 1. The following table shows how it works in detail:

Example : This example illustrates the use of the spaceship operator in PHP.

Please Login to comment...

Similar reads.

  • PHP-Operators
  • Web Technologies
  • How to Use ChatGPT with Bing for Free?
  • 7 Best Movavi Video Editor Alternatives in 2024
  • How to Edit Comment on Instagram
  • 10 Best AI Grammar Checkers and Rewording Tools
  • 30 OOPs Interview Questions and Answers (2024)

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Home » PHP Tutorial » PHP Operators

PHP Operators

Summary : in this tutorial, you will learn about PHP operators and how to use them effectively in your script.

An operator takes one or more values, known as operands, and performs a specific operation on them.

For example, the + operator adds two numbers and returns the sum of them.

PHP supports many kinds of operators:

Arithmetic Operators

Assignment operators, bitwise operators, comparison operators.

  • Increment/Decrement Operators

Logical Operators

  • Concatenating Operators

The arithmetic operators require numeric values. If you apply them to non-numeric values, they’ll convert them to numeric values before carrying the arithmetic operation.

The following are the list of arithmetic operators:

The following example uses the arithmetic operators:

Comparison operators allow you to compare two operands.

A comparison operator returns a Boolean value, either true or false . If the comparison is truthful, the comparison operator returns true , otherwise, it returns false .

The following are the list of comparison operators in PHP:

Logical operators allow you to construct logical expressions. A logical operator returns a Boolean value.

PHP provides the following logical operators:

Bitwise operators perform operations on the binary representation of the operands. The following illustrates bitwise operators in PHP:

Incrementing/ Decrementing Operators

Increment (++)  and decrement (–) operators give you a quick way to increase and decrease the value of a variable by 1.

The following table illustrates the increment and decrement operators:

Concatenating Operator

Concatenating operator (.) allows you to combine two strings into one. It appends the second string to the first one and returns the combined string. For example:

Assignment operator ( = ) assigns a value to a variable and returns a value. The operand on the left is always a variable, while the operand on the right can be a literal value, variable, expression, or a function call that returns a value. For example:

In the first expression, we assigned $x  variable value 10 .  In the second one, we assigned the value of $x to $y variable. The third one is a little bit complicated. First, we assigned 20 to $x . The assignment operator ( = ) returns 20 and then 20 is assigned to $z  variable.

Besides the basic assignment operator( = ), PHP provides you with some assignment operators:

  • plus-equal  +=
  • minus-equal  -=
  • divide-equal  /=
  • multiplication-equal  *=
  • modulus-equal  %=
  • XOR-equal  ^=
  • AND-equal  &=
  • OR-equal  |=
  • concatenate-equal  .=

PHP operators precedence

The precedence of an operator decides which order the operator is evaluated in an expression.

PHP assigned each operator precedence. Some operators have the same precedence, e.g., precedences of the addition ( + ) and subtraction( - ) are equal.

However, some operators have higher precedence than others.

For example, the precedence of the multiplication operator ( * ) is higher than the precedence of the add( + ) and the subtract ( - ) operators:

Because the precedence of the multiplication operator ( * ) is higher than the precedence of the add( + ) operator, PHP evaluates the multiplication operator ( * ) first and then add operator ( * ) second.

To force the evaluation in a particular order, you put the expression inside parentheses () , for example:

In this tutorial, you have briefly learned about the most commonly used PHP operators.

assignment operator in php

PHP Expressions and Operators

Operators are used to perform operations on variables and values. When we’re talking about operators we’re basically talking about “math”. By operator I mean things like multiplication and division signs.

As you might imagine there are tons of operators. Certainly enough to get lost in. The reality is, a lot of these you won’t use on a regular basis or they’ll make more sense if we cover them in a different lesson.

PHP Operators  can be separated into the following categories:

PHP Arithmetic Operators

Php assignment operators, php incrementing / decrementing operators, php comparison operators, php logical operators.

  • Bitwise Operators

PHP Array Operators

  • PHP String Operators

An operator is something that takes one or more values (or expressions, in programming jargon) and yields another value (so that the construction itself becomes an expression).

Operator Precedence

The precedence of an operator specifies how “tightly” it binds two expressions together. For example, in the expression  1 + 5 * 3 , the answer is  16  and not  18  because the multiplication (“*”) operator has a higher precedence than the addition (“+”) operator. Parentheses may be used to force precedence, if necessary. For instance:  (1 + 5) * 3  evaluates to  18 .

When operators have equal precedence their associativity decides how the operators are grouped. For example “-” is left-associative, so  1 – 2 – 3  is grouped as  (1 – 2) – 3  and evaluates to  -4 . “=” on the other hand is right-associative, so  $a = $b = $c  is grouped as  $a = ($b = $c) .

Operators of equal precedence that are non-associative cannot be used next to each other, for example  1 < 2 > 1  is illegal in PHP. The expression  1 <= 1 == 1  on the other hand is legal, because the  ==  operator has lesser precedence than the  <=  operator.

Although parentheses are not strictly needed, the readability of the code can often be increased by explicitly grouping rather than by using the implicit predominance and association of the operator.

The following table lists the operators in order of precedence, with the highest-precedence ones at the top. Operators on the same line have equal precedence, in which case associativity decides grouping.

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

The PHP assignment operators are used with numeric values to write a value to a variable.

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.

The PHP increment operators are used to increment a variable’s value.

The PHP decrement operators are used to decrement a variable’s value.

The PHP comparison operators are used to compare two values (number or string):

Comparison operators, as their name implies, allow you to compare two values. You may also be interested in viewing the type comparison tables, as they show examples of various type related comparisons.

The PHP logical operators are used to combine conditional statements.

Bitwise Operator In PHP

The detailed illustrations of them are out of these lessons and just we introduce them and their names:

The PHP array operators are used to compare arrays.

String operators in PHP :

PHP has two operators that are specially designed for strings.

Operator Name Example Result. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2.=Concatenation assignment$txt1 .= $txt2Appends $txt2 to $txt1

Related Posts

Lightweight template engine with php, php conditional statements, php constants, about the author.

' src=

Nohman Habib

I basically work in the CMS, like Joomla and WordPress and in framework like Laravel and have keen interest in developing mobile apps by utilizing hybrid technology. I also have experience working in AWS technology. In terms of CMS, I give Joomla the most value because I found it so much user freindly and my clients feel so much easy to manage their project in it.

Your email address will not be published. Required fields are marked *

Email Address: *

Save my name, email, and website in this browser for the next time I comment.

ABOUT CODINGACE

My name is Nohman Habib and I am a web developer with over 10 years of experience, programming in Joomla, Wordpress, WHMCS, vTiger and Hybrid Apps. My plan to start codingace.com is to share my experience and expertise with others. Here my basic area of focus is to post tutorials primarily on Joomla development, HTML5, CSS3 and PHP.

CEO: codingace.com

Request a Quote

Please complete all required fields!

assignment operator in php

Calisto Code

PHP Operators: Understanding the Building Blocks of PHP Programming

PHP Operators

As one of the most popular programming languages used on the web, PHP is a powerful tool for creating dynamic and interactive web applications. Whether you’re building a simple contact form or a complex content management system, understanding PHP operators is essential for writing efficient and effective code.

In this article, we’ll explore the different types of PHP operators and how they can be used to manipulate values, make comparisons, and control program flow. By the end of this article, you’ll have a comprehensive understanding of the building blocks of PHP programming .

What are Operators?

In programming, operators are special symbols or keywords that are used to perform specific actions on values or variables. In PHP, there are several different types of operators, each with their own set of rules and behaviors.

Operators can be used to perform mathematical operations, such as addition or subtraction, as well as comparison operations, such as checking if one value is equal to another. They can also be used to control program flow, such as executing code only if a certain condition is met.

Types of Operators

In PHP, there are several types of operators, each with its own set of rules and behaviors. Let’s take a closer look at each type.

Arithmetic Operators

Arithmetic operators are used to perform mathematical operations on values. PHP supports the following arithmetic operators:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%)
  • Exponentiation (**)

For example, the following code uses the addition operator to add two numbers:

Assignment Operators

Assignment operators are used to assign values to variables. In PHP, the following assignment operators are supported:

  • Assignment (=)
  • Addition assignment (+=)
  • Subtraction assignment (-=)
  • Multiplication assignment (*=)
  • Division assignment (/=)
  • Modulus assignment (%=)

For example, the following code uses the addition assignment operator to add a value to an existing variable:

Comparison Operators

Comparison operators are used to compare values and determine if they are equal, greater than, or less than each other. PHP supports the following comparison operators:

  • Not equal (!=)
  • Identical (===)
  • Not identical (!==)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)

For example, the following code uses the equal operator to check if two values are equal:

Logical Operators

Logical operators are used to combine multiple conditions and determine if they are true or false. PHP supports the following logical operators:

  • And (&&)

For example, the following code uses the and operator to check if two conditions are both true:

Increment and Decrement Operators

Increment and decrement operators are used to increase or decrease the value of a variable by one. PHP supports the following increment and decrement operators:

  • Increment (++)
  • Decrement (–)

For example, the following code uses the increment operator to increase the value of a variable by one:

String Operators

String operators are used to concatenate two or more strings together. In PHP, the concatenation operator is the period (.) symbol. For example, the following code uses the concatenation operator to concatenate two strings:

Array Operators

Array operators are used to manipulate arrays. PHP supports the following array operators:

  • Equality (==)
  • Identity (===)
  • Inequality (!=)
  • Non-identity (!==)

For example, the following code uses the union operator to combine two arrays:

Operator Precedence

When multiple operators are used in a single expression, the order in which they are evaluated is determined by their precedence. Operator precedence defines the order in which operators are evaluated in an expression.

For example, in the expression $a + $b * $c , the multiplication operator has a higher precedence than the addition operator. This means that $b * $c is evaluated first, and then the result is added to $a .

It’s important to understand operator precedence when writing complex expressions, as it can affect the outcome of the expression. To ensure that expressions are evaluated in the correct order, you can use parentheses to group sub-expressions.

In PHP programming, operators are essential for manipulating values, making comparisons, and controlling program flow. There are several types of operators in PHP, including arithmetic, assignment, comparison, logical, increment and decrement, string, and array operators.

By understanding the different types of operators and their behaviors, you can write more efficient and effective PHP code. It’s important to remember operator precedence when writing complex expressions, and to use parentheses to group sub-expressions to ensure that expressions are evaluated in the correct order.

Whether you’re a beginner or an experienced PHP programmer, understanding operators is a crucial part of building dynamic and interactive web applications. With this comprehensive guide to PHP operators, you’ll have the knowledge you need to take your PHP programming skills to the next level.

📕 Related articles about PHP

  • PHP Callback Functions
  • How to Use PHP for Session Management
  • PHP Strings: The Comprehensive Guide
  • PHP Form Validation
  • PHP Form Handling: A Comprehensive Guide

' src=

Patel is a skilled software developer with a passion for front-end stacks and a specific interest in HTML, CSS, and JavaScript. With 3 years of experience in the industry, Patel has developed a deep understanding of front-end web development and is well-versed in the latest industry trends and best practices.

Similar Posts

PHP RegEx

If you’re a PHP developer, chances are you’ve heard of regular expressions, also known as RegEx. RegEx is a powerful tool that can help you search, match, and manipulate text. With RegEx, you can easily search for patterns in strings, validate data, and even extract information from text. In this article, we’ll explore the world…

PHP Filters: An In-Depth Overview

PHP Filters: An In-Depth Overview

PHP is a popular server-side scripting language that is widely used in web development. It is known for its ease of use, flexibility, and the abundance of frameworks and libraries available for it. With PHP, developers can easily create dynamic applications that can interact with databases, messaging systems, and other web services. One of the…

PHP Include: A Comprehensive Guide

PHP Include: A Comprehensive Guide

You must have heard of PHP include if you are a PHP developer. PHP include is a powerful feature that allows you to reuse code and make your code more modular. In this article, we will dive deep into the world of PHP include, and learn how to use it effectively. What is PHP Include?…

How to Use PHP for Error Handling and Logging

How to Use PHP for Error Handling and Logging

As a software developer, encountering errors is a common occurrence when building applications. It can be frustrating and time-consuming to debug these errors without proper error handling and logging mechanisms in place. PHP offers a robust error handling and logging system that makes it easier to detect and resolve issues in your code. In this…

PHP XML Parser: A Comprehensive Guide

PHP XML Parser: A Comprehensive Guide

Introduction The world we live in today is heavily reliant on data. Without data, our world would come to a standstill. In fact, data is considered the new oil in today’s fast-paced world where technology is rapidly advancing. As a result, companies are investing heavily in their data departments to stay ahead of the competition….

Understanding PHP Access Modifiers

Understanding PHP Access Modifiers

When it comes to object-oriented programming in PHP, access modifiers play a crucial role in how classes and their properties and methods can be accessed within the program. Access modifiers are essentially keywords defining the level of access provided to certain class elements. PHP has three different access modifiers: public, private, and protected. In this…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Save my name, email, and website in this browser for the next time I comment.

PHP Advance

Operators - php basics.

Operators are symbols that instruct the PHP processor to carry out specific actions. For example, the addition ( + ) symbol instructs PHP to add two variables or values, whereas the greater-than ( > ) symbol instructs PHP to compare two values.

PHP operators are grouped as follows:

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators
  • Conditional assignment operators

Arithmetic Operators

The PHP arithmetic operators are used in conjunction with numeric values to perform common arithmetic operations such as addition, subtraction, multiplication, and so on.

Sample usage of Arithmetic Operators:

Assignment Operators

Assignment operators are used to assign values to variables.

Sample usage of Assignment Operators:

Comparison Operators

Comparison operators are used to compare two values in a Boolean fashion.

Sample usage of Comparison Operators:

Increment / Decrement Operators

Increment operators are used to increment a variable's value while decrement operators are used to decrement.

Sample usage of Increment / Decrement Operators:

Logical Operators

Logical operators are typically used to combine conditional statements.

Sample usage of Logical Operators:

String Operators

String operators are specifically designed for strings.

Sample usage of String Operators:

Array Operators

Array operators are used to compare arrays.

Conditional Assignment Operators

Conditional assignment operators are used to set a value depending on conditions.

Sample usage of Conditional Assignment Operators:

Create the following variables: $num1 , $num2 , $num3 . Assign the integer 3 to $num1 and 9 to $num2 . Multiply $num1 by $num2 and assign the product to $num3 . Print the result on $num3

  • Introduction
  • What is PHP?
  • What can you do with PHP?
  • Why use PHP?
  • Requirements for this tutorial
  • Echo and Print
  • Conditionals
  • Switch...Case
  • Foreach Loop
  • Do...While Loop
  • Break/Continue
  • Sorting Arrays
  • Date and Time
  • Include Files
  • File Handling
  • File Upload
  • Form Validation
  • Error Handling
  • Classes and Objects
  • Constructor and Destructor
  • Access Modifiers
  • Inheritance
  • Abstract Classes

PHP Functions and Methods

  • PHP Functions and Methods Index

CodedTag

  • Conditional Operators

Conditional Assignment Operator in PHP is a shorthand operator that allow developers to assign values to variables based on certain conditions.

In this article, we will explore how the various Conditional Assignment Operators in PHP simplify code and make it more readable.

Let’s begin with the ternary operator.

Ternary Operator Syntax

The Conditional Operator in PHP, also known as the Ternary Operator, assigns values to variables based on a certain condition. It takes three operands: the condition, the value to be assigned if the condition is true, and the value to be assigned if the condition is false.

Here’s an example:

In this example, the condition is $score >= 60 . If this condition is true, the value of $result is “Pass”. Otherwise, the value of $result is “Fail”.

To learn more, visit the PHP ternary operator tutorial . Let’s now explore the section below to delve into the Null Coalescing Operator in PHP.

The Null Coalescing Operator (??)

The Null Coalescing Operator, also known as the Null Coalescing Assignment Operator, assigns a default value to a variable if it is null. The operator has two operands: the variable and the default value it assigns if the variable is null. Here’s an example:

So, In this example, if the $_GET['name'] variable is null, the value of $name is “Guest”. Otherwise, the value of $name is the value of $_GET['name'] .

Here’s another pattern utilizing it with the assignment operator. Let’s proceed.

The Null Coalescing Assignment Operator (??=)

The Null Coalescing Operator with Assignment, also known as the Null Coalescing Assignment Operator, assigns a default value to a variable if it is null. The operator has two operands: the variable and the default value it assigns if the variable is null. Here’s an example:

So, the value of $name is null. The Null Coalescing Assignment Operator assigns the value “Guest” to $name. Therefore, the output of the echo statement is “Welcome,”Guest!”.

Moving into the following section, you’ll learn how to use the Elvis operator in PHP.

The Elvis Operator (?:)

In another hand, The Elvis Operator is a shorthand version of the Ternary Operator. Which assigns a default value to a variable if it is null. It takes two operands: the variable and the default value to be assigned if the variable is null. Here’s an example:

In this example, if the $_GET['name'] variable is null, the value“Guest” $name s “Guest”. Otherwise, the value of $name is the value of $_GET['name'] .

Let’s summarize it.

Wrapping Up

The Conditional Assignment Operators in PHP provide developers with powerful tools to simplify code and make it more readable. You can use these operators to assign values to variables based on certain conditions, assign default values to variables if they are null, and perform shorthand versions of conditional statements. By using these operators, developers can write more efficient and elegant code.

Did you find this article helpful?

 width=

Sorry about that. How can we improve it ?

  • Facebook -->
  • Twitter -->
  • Linked In -->
  • Install PHP
  • Hello World
  • PHP Constant
  • PHP Comments

PHP Functions

  • Parameters and Arguments
  • Anonymous Functions
  • Variable Function
  • Arrow Functions
  • Variadic Functions
  • Named Arguments
  • Callable Vs Callback
  • Variable Scope

Control Structures

  • If-else Block
  • Break Statement

PHP Operators

  • Operator Precedence
  • PHP Arithmetic Operators
  • Assignment Operators
  • PHP Bitwise Operators
  • PHP Comparison Operators
  • PHP Increment and Decrement Operator
  • PHP Logical Operators
  • PHP String Operators
  • Array Operators
  • Ternary Operator
  • PHP Enumerable
  • PHP NOT Operator
  • PHP OR Operator
  • PHP Spaceship Operator
  • AND Operator
  • Exclusive OR
  • Spread Operator
  • Null Coalescing Operator

Data Format and Types

  • PHP Data Types
  • PHP Type Juggling
  • PHP Type Casting
  • PHP strict_types
  • Type Hinting
  • PHP Boolean Type
  • PHP Iterable
  • PHP Resource
  • Associative Arrays
  • Multidimensional Array

String and Patterns

  • Remove the Last Char

Tutorials Class - Logo

  • PHP Operators

Operators are used to perform operations on variables and values.

PHP divides the operators in the following groups:

Arithmetic operators

Assignment operators.

  • Comparison operators
  • Increment/Decrement operators
  • Logical operators
  • String operators
  • Array operators

PHP Operators with Example

The PHP arithmetic operators are used with numeric values to perform common arithmetical operations, such as addition, subtraction, multiplication etc.

  • Operator Name Example Result
  • + Addition $x + $y Sum of $x and $y
  • - Subtraction $x - $y Difference of $x and $y
  • * Multiplication $x * $y Product of $x and $y
  • / Division $x / $y Quotient of $x and $y
  • % Modulus $x % $y Remainder of $x divided by $y
  • ** Exponentiation $x ** $y Result of raising $x to the $y'th power (Introduced in PHP 5.6)

Run : http://ideone.com/EwZM3b

10 6 16 4 0 64

The PHP assignment operators are used with numeric values to write a value to a variable.

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.

  • Assignment Same as… Description
  • x = y x = y The left operand gets set to the value of the expression on the right
  • x += y x = x + y Addition
  • x -= y x = x - y Subtraction
  • x *= y x = x * y Multiplication
  • x /= y x = x / y Division
  • x %= y x = x % y Modulus

Run : http://ideone.com/U8sJHv

20 40 20 400 20 0

Comparison Operators

The PHP comparison operators are used to compare two values (number or string):

  • == Equal $x == $y Returns true if $x is equal to $y
  • === Identical $x === $y Returns true if $x is equal to $y, and they are of the same type
  • != Not equal $x != $y Returns true if $x is not equal to $y
  • <> Not equal $x <> $y Returns true if $x is not equal to $y
  • !== Not identical $x !== $y Returns true if $x is not equal to $y , or they are not of the same type
  • > Greater than $x > $y Returns true if $x is greater than $y
  • < Less than $x < $y Returns true if $x is less than $y
  • >= Greater than or equal to $x >= $y Returns true if $x is greater than or equal to $y
  • <= Less than or equal to $x <= $y Returns true if $x is less than or equal to $y

Increment / Decrement Operators

The PHP decrement operators are used to decrement a variable’s value.

  • Operator Name Description
  • ++$x Pre-increment Increments $x by one, then returns $x
  • $x++ Post-increment Returns $x, then increments $x by one
  • --$x Pre-decrement Decrements $x by one, then returns $x
  • $x-- Post-decrement Returns $x , then decrements $x by one

Logical Operators

The PHP logical operators are used to combine conditional statements.

  • and And $x and $y True if both $x and $y are true
  • or Or $x or $y True if either $x or $y is true
  • xor Xor $x xor $y True if either $x or $y is true, but not both
  • && And $x && $y True if both $x and $y are true
  • || Or $x || $y True if either $x or $y is true
  • ! Not !$x True if $x is not true

String Operators

PHP has two operators that are specially designed for strings.

  • . Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2
  • .= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1

Array Operators

The PHP array operators are used to compare arrays.

  • + Union $x + $y Union of $x and $y
  • == Equality $x == $y Returns true if $x and $y have the same key/value pairs
  • === Identity $x === $y Returns true if $x and $y have the same key/value pairs in the same order and of the same types
  • != Inequality $x != $y Returns true if $x is not equal to $y
  • <> Inequality $x <> $y Returns true if $x is not equal to $y
  • !== Non-identity $x !== $y Returns true if $x is not identical to $y

Share this post:

  • Previous Page
  • PHP Tutorial Index
  • PHP Introduction
  • PHP Terminology
  • PHP Installation
  • PHP Comments
  • PHP Variables
  • PHP Data Types
  • PHP Decision Making
  • PHP Functions
  • PHP Constants
  • PHP Array Functions
  • PHP String Handling
  • PHP Advanced
  • PHP Forms Handling
  • PHP File Upload
  • PHP File Handling
  • PHP Send Mail
  • PHP File Inclusion
  • PHP Date and Time
  • PHP Cookies
  • PHP Session
  • PHP OOP Introduction
  • Objects In PHP
  • PHP MySQL Tutorial
  • PHP : MySQL Database
  • PHP : MySQL Connect
  • PHP : MySQL Create Database
  • PHP : MySQL Create Table
  • PHP : MySQL INSERT Statement
  • PHP : MySQL Select Data
  • PHP : MySQL UPDATE Statement
  • PHP : MySQL DELETE Statement

IMAGES

  1. PHP ASSIGNMENT OPERATORS

    assignment operator in php

  2. PHP Tutorial For Beginners 16

    assignment operator in php

  3. Operators in PHP

    assignment operator in php

  4. PHP operators Tutorial Example

    assignment operator in php

  5. PHP Assignment Operators

    assignment operator in php

  6. Assignment Operator in PHP #6

    assignment operator in php

VIDEO

  1. PHP Variable Scope & Operator

  2. How to Perform Arithmetic Operation using PHP Dynamically

  3. assignment operator simple program in java..#java # assignment_operator

  4. Assignment Operator & Comparison Operator in Javascript

  5. 3

  6. Belajar PHP : Penggunaan Operator

COMMENTS

  1. PHP: Assignment

    Assignment Operators. The basic assignment operator is "=". Your first inclination might be to think of this as "equal to". ... An exception to the usual assignment by value behaviour within PHP occurs with object s, which are assigned by reference. Objects may be explicitly copied via the clone keyword. Assignment by Reference.

  2. PHP Operators

    PHP Assignment Operators. The PHP assignment operators are used with numeric values to write a value to a variable. 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.

  3. PHP Assignment Operators

    Use PHP assignment operator ( =) to assign a value to a variable. The assignment expression returns the value assigned. Use arithmetic assignment operators to carry arithmetic operations and assign at the same time. Use concatenation assignment operator ( .= )to concatenate strings and assign the result to a variable in a single statement.

  4. Reference assignment operator in PHP, =&

    It's called assignment by reference, which, to quote the manual, "means that both variables end up pointing at the same data, and nothing is copied anywhere". The only thing that is deprecated with =& is "assigning the result of new by reference" in PHP 5 , which might be the source of any confusion.

  5. PHP Assignment Operators

    PHP Assignment Operators. PHP assignment operators applied to assign the result of an expression to a variable. = is a fundamental assignment operator in PHP. It means that the left operand gets set to the value of the assignment expression on the right. Operator.

  6. PHP assignment operators

    PHP Assignment Operators Last update on August 19 2022 21:51:14 (UTC/GMT +8 hours) Description. Assignment operators allow writing a value to a variable. The first operand must be a variable and the basic assignment operator is "=". The value of an assignment expression is the final value assigned to the variable.

  7. What is the assignment operator in PHP and how to use it

    We assign values to variables with assignment operators. The base assignment operator is equal (=). I assume that you understand this in the examples and narratives that pass. A single equal sign allows us to assign the desired value to the desired variable. Let's show the other operators on a table. These operators are unified assignment ...

  8. PHP

    Assignment Operators. The basic assignment operator is =, which takes the right-hand operand and assigns it to the variable that is the left-hand operand. PHP also has a number of additional assignment operators that are shortcuts for longer expressions. Arithmetic Assignment Operators. There is an assignment operator for each arithmetic ...

  9. PHP Assignment Operators

    In this tutorial, you shall learn about Assignment Operators in PHP, different Assignment Operators available in PHP, their symbols, and how to use them in PHP programs, with examples. Assignment Operators. Assignment Operators are used to perform to assign a value or modified value to a variable. Assignment Operators Table

  10. PHP Assignment Operators: Performing Calculations

    PHP assignment operators enable you to frequently engage in performing calculations and operations on variables, requiring the assignment of results to other variables. Consequently, this is precisely where assignment operators prove indispensable, allowing you to seamlessly execute an operation and assign the result to a variable within a ...

  11. PHP

    PHP - Assignment Operators Examples - You can use assignment operators in PHP to assign values to variables. Assignment operators are shorthand notations to perform arithmetic or other operations while assigning a value to a variable. For instance, the = operator assigns the value on the right-hand side to the variable on the left-han

  12. PHP Operators

    These operators are nothing but symbols needed to perform operations of various types. Given below are the various groups of operators: Arithmetic Operators. Logical or Relational Operators. Comparison Operators. Conditional or Ternary Operators. Assignment Operators. Spaceship Operators (Introduced in PHP 7)

  13. PHP Operators

    An operator takes one or more values, known as operands, and performs a specific operation on them. For example, the + operator adds two numbers and returns the sum of them. PHP supports many kinds of operators: Arithmetic Operators. Assignment Operators. Bitwise Operators. Comparison Operators.

  14. PHP Expressions and Operators

    PHP Assignment Operators. The PHP assignment operators are used with numeric values to write a value to a variable. 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.

  15. PHP Operators: Understanding the Building Blocks of PHP Programming

    There are several types of operators in PHP, including arithmetic, assignment, comparison, logical, increment and decrement, string, and array operators. By understanding the different types of operators and their behaviors, you can write more efficient and effective PHP code. It's important to remember operator precedence when writing ...

  16. PHP

    Though it's still in danger of readability fault or mixing = and == operators. But mixing logical and assignment operators in one statement is bad. This is called obfuscation and perl write-only style, makes reading this code harder.

  17. PHP Operators

    Operators are symbols that instruct the PHP processor to carry out specific actions. For example, the addition (+) symbol instructs PHP to add two variables or values, whereas the greater-than (>) symbol instructs PHP to compare two values.PHP operators are grouped as follows: Arithmetic operators; Assignment operators; Comparison operators; Increment/Decrement operators

  18. PHP Conditional Operator: Examples and Tips

    Conditional Assignment Operator in PHP is a shorthand operator that allow developers to assign values to variables based on certain conditions. In this article, we will explore how the various Conditional Assignment Operators in PHP simplify code and make it more readable. Let's begin with the ternary operator. Ternary Operator Syntax

  19. PHP Operators with Examples

    The PHP assignment operators are used with numeric values to write a value to a variable. 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.