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.

Operator Name Example Result Try it
+ 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

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.

Assignment Same as... Description Try it
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

Advertisement

PHP Comparison Operators

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

Operator Name Example Result Try it
== 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
<=> Spaceship $x <=> $y Returns an integer less than, equal to, or greater than zero, depending on if $x is less than, equal to, or greater than $y. Introduced in PHP 7.

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.

Operator Same as... Description Try it
++$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

PHP Logical Operators

The PHP logical operators are used to combine conditional statements.

Operator Name Example Result Try it
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

PHP String Operators

PHP has two operators that are specially designed for strings.

Operator Name Example Result Try it
. Concatenation $txt1 . $txt2 Concatenation of $txt1 and $txt2
.= Concatenation assignment $txt1 .= $txt2 Appends $txt2 to $txt1

PHP Array Operators

The PHP array operators are used to compare arrays.

Operator Name Example Result Try it
+ 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

PHP Conditional Assignment Operators

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

Operator Name Example Result Try it
?: Ternary $x = ? : Returns the value of $x.
The value of $x is if = TRUE.
The value of $x is if = FALSE
?? Null coalescing $x = ?? Returns the value of $x.
The value of $x is if exists, and is not NULL.
If does not exist, or is NULL, the value of $x is .
Introduced in PHP 7

Get Certified

COLOR PICKER

colorpicker

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected]

Top Tutorials

Top references, top examples, get certified.

  • 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.

OperatorSymbolExampleDescription
Simple Assignment=x = 5Assigns value of 5 to variable x.
Addition Assignment+= Assigns the result of to x.
Subtraction Assignment-= Assigns the result of to x.
Multiplication Assignment*= Assigns the result of to x.
Division Assignment/= Assigns the result of to x.
Modulus Assignment%= Assigns the result of to x.

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.

  • 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

Example Equivalent Operation
$a += $b $a = $a + $b Addition
$a -= $b $a = $a - $b Subtraction
$a *= $b $a = $a * $b Multiplication
$a /= $b $a = $a / $b Division
$a %= $b $a = $a % $b Modulus
$a **= $b $a = $a ** $b Exponentiation

Bitwise Assignment Operators

Example Equivalent Operation
$a &= $b $a = $a & $b Bitwise And
$a |= $b $a = $a | $b Bitwise Or
$a ^= $b $a = $a ^ $b Bitwise Xor
$a <<= $b $a = $a << $b Left Shift
$a >>= $b $a = $a >> $b Right Shift

Other Assignment Operators

Example Equivalent Operation
$a .= $b $a = $a . $b String Concatenation
$a ??= $b $a = $a ?? $b Null Coalesce
  • arithmetic operators
  • bitwise operators
  • null coalescing operator

Improve This Page

User contributed notes.

To Top

garanews's avatar

Operators are used to perform operations on variables and values.

Arithmetic Operators

PHP has the following basic arithmetic operators to perform common mathematical operations:

Operator Name Description
Addition returns the sum of and
Subtraction returns the difference of and
Multiplication returns the product of and
Division returns the quotient of and
Modulo returns the integer remainder of divided by
Exponentiation returns raised to the power

The division operator returns a float unless its operands are integers and the result is a whole number, in which case it returns an integer.

Operands of modulo are converted to integers before calculating. The modulo result will have the same sign as the dividend.

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 operator above.

Operator Name Description
Addition Assignment is short for
Subtraction Assignment is short for
Multiplication Assignment is short for
Division Assignment is short for
Modulo Assignment is short for
Exponentiation Assignment is short for

Bitwise Assignment Operators

There is an assignment operator for each bitwise operator (see below).

Operator Name Description
And Assignment is short for
Or Assignment is short for
Xor Assignment is short for
Left Shift Assignment is short for
Right Shift Assignment is short for

Bitwise Operators

The bitwise operators manipulate individual bits in an integer.

Operator Name Description
And result has bit set only where both operands have that bit set.
Or result has bit set if either operand has that bit set.
Xor result has bit set only if only one operand has that bit set.
Not takes a single operand and inverts each bit in it.
Left shift means ‘s bits are shifted to the left spaces. zeros are inserted from the right, and the leftmost $b bits are discarded.
Right shift means ‘s bits are shifted to the right spaces. copies of the leftmost bit are inserted from the left, and the rightmost $b bits are discarded.

Comparison Operators

Operator Name Description
Equal is if and are equal after type juggling.
Identical is if and are equal and the same type.
Not Equal is if and are not equal after type juggling.
Not Equal is if and are not equal after type juggling.
Not Identical is if and are not equal or not the same type.
Less Than is if is less than .
Greater Than is if is greater than .
Less Than or Equal to is if is less than or equal to .
Greater Than or Equal to is if is greater than or equal to .
Spaceship returns an integer greater than, less than or equal to zero when is greater than, less than, or equal to respectively.

Incrementing/Decrementing Operators

Operator Name Description
Preincrement Increments by one then returns .
Postincrement Returns , then increments by one.
Predecrement Decrements by one, then returns .
Postdecrement Returns , then decrements by one.

Logical Operators

Operator Name Description
And is only if and are both .
Or is if either or is .
Xor is only when only one of or is .
Not is when $x is and when $x is .
And is only if and are both .
Or is if either or is .

While and and && , and or and || , have the same meaning, they operate at different precedences. Importantly, && and || have higher precedence than = while and and or do not.

String Operators

Operator Name Description
Concatenate Concatenates the left and right operands
Concatenate assignment Concatenates the left and right operands and assigns the value to the left operand.

Array Operators

Operator Name Description
Union returns the union of arrays and .
Union Assignment assigns the union of $x and $y to $x.
Equal is if and consist of the same key/value pairs.
Identical is if and have the same key/value pairs, in the same order, and of the same types.
Not Equal is if and do not have the same key/value pairs.
Not Equal is if and do not have the same key/value pairs.
Not Identical is if is .

When using + with arrays, it returns an array of the right operand appended to the left operand. In cases where there are matching keys in the arrays, the elements from the left operand will be used and the matching elements from the right operand will be discarded.

Type Operators

Operator Name Description
Instance of returns if is an instance of the class .

SomeClass can be a class name, a variable of the given class, or a string containing the class name.

All contributors

Anonymous contributor's avatar

Looking to contribute?

  • Learn more about how to get involved.
  • Edit this page on GitHub to fix an error or make an improvement.
  • Submit feedback to let us know how we can improve Docs.

Learn PHP on Codecademy

Computer science.

CodedTag

  • Assignment Operators

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 single statement.

In the following sections, we’ll delve into the different types of PHP assignment operators and explore how to use them.

Table of Contents

Php arithmetic assignment operators, php bitwise assignment operators.

  • Null Coalescing Operator

Assigning a Reference to a PHP Variable

Other assignment operators, wrapping up.

The most commonly used assignment operator in PHP is the equals sign (=). For instance, in the following code, the value 10 is assigned to the variable $x:

Now, let’s explore each type with examples:

Numeric data undergoes mathematical operations through the utilization of arithmetic operators. In PHP, this is where arithmetic assignment operators come into play, employed to perform these operations. The arithmetic assignment operators include:

  • += or $x + $y (Addition Assignment Operator)
  • -= or $x - $y (Subtraction Assignment Operator)
  • *= or $x * $y (Multiplication Assignment Operator)
  • /= or $x / $y (Division Assignment Operator)
  • %= or $x % $y (Modulus Assignment Operator)
  • **= or $x ** $y (Exponentiation Assignment Operator)

Consider the following example:

In this example, the addition assignment operator increases the value of $x by 5, and then assigns the result back to $x, producing an output of 15.

You can leverage these arithmetic assignment operators to perform complex calculations in a single statement, making your code more concise and easier to read. For more details, refer to this tutorial .

One crucial aspect of computer science involves the manipulation of binary bits in PHP. Let’s delve into one of the more complex assignment operators—specifically, the PHP bitwise operators.

Developers use bitwise operators to manipulate data at the bit level. PHP bitwise assignment operators perform bitwise operations. Here are the bitwise assignment operators:

  • &= or $x & $y (Bitwise AND Assignment Operator)
  • |= or $x | $y (Bitwise OR Assignment Operator)
  • ^= or $x ^ $y (Bitwise XOR Assignment Operator)
  • ~= or $x ~ $y (Bitwise NOT Assignment Operator)
  • <<= or $x << $y (Left Shift Assignment Operator)
  • >>= or $x >> $y (Right Shift Assignment Operator)

Let’s illustrate with an example:

In this example, a bitwise OR operation is performed between the values of $x and 2 using the bitwise OR assignment operator. The result is then assigned to $x, yielding an output of 7.

Here is a full explanation along with more examples of bitwise operators .

Let’s move to the section below to understand the Null Coalescing Operator in PHP.

Furthermore, developers use the null coalescing operator to assign a default value to a variable if it is null. The double question mark (??) symbolizes the null coalescing operator. Consider the following example:

In this example, the null coalescing operator is used to assign the value ‘John Doe’ to the variable $fullName. If $name is null, the value ‘John Doe’ will be assigned to $fullName.

The null coalescing operator simplifies code by enabling the assignment of default values to variables. By reading this tutorial , you will gain more information about it

Anyway, assigning a reference in PHP is one of the language’s benefits, enabling developers to set a value and refer back to it anywhere during the script-writing process. Let’s move to the section below to take a closer look at this concept.

Furthermore, individuals use the reference assignment operator =& to assign a reference to a variable rather than copying the value of the variable. Consider the following example:

In this example, a reference to the variable $x is created using the reference assignment operator. The value 10 is then assigned to $x, and the output displays the value of $y. Since $y is a reference to $x, it also changes to 10, resulting in an output of 10.

The reference assignment operator proves useful when working with large data sets, enabling you to avoid copying large amounts of data.

Let’s explore some other assignment operators in the paragraphs below.

In addition to the arithmetic, bitwise, null coalescing, and reference assignment operators, PHP provides other assignment operators for specific use cases. These operators are:

  • .= (Concatenation Assignment Operator)
  • ??= (Null Coalescing Assignment Operator)

Now, let’s explore each of these operators in turn:

Concatenation Assignment Operator: Used to concatenate a string onto the end of another string. For example:

In this example, the concatenation assignment operator appends the value of $string2 to the end of $string1, resulting in the output “Hello World!”.

The Null Coalescing Assignment Operator is employed to assign a default value to a variable when it is detected as null. For example:

In this example, the null coalescing assignment operator assigns the value ‘John Doe’ to the variable $name. If $name is null, the value ‘John Doe’ will be assigned to $name.

Let’s summarize it.

we’ve taken a comprehensive look at the different types of PHP assignment operators and how to use them. Assignment operators are essential tools for any PHP developer, facilitating calculations and operations on variables while assigning results to other variables in a single statement.

Moreover, leveraging assignment operators allows you to make your code more concise, easier to read, and helps in avoiding common programming errors.

Did you find this article helpful?

 width=

Sorry about that. How can we improve it ?

  • Facebook -->
  • Twitter -->
  • Linked In -->
  • PHP History
  • Install PHP
  • Hello World
  • PHP Constant
  • Predefined Constants
  • 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 Condition
  • If-else Block
  • Break Statement

PHP Operators

  • Operator Precedence
  • PHP Arithmetic Operators
  • PHP Bitwise Operators
  • PHP Comparison Operators
  • PHP Increment and Decrement Operator
  • PHP Logical Operators
  • PHP String Operators
  • Array Operators
  • Conditional Operators
  • Ternary Operator
  • PHP Enumerable
  • PHP NOT Operator
  • PHP OR Operator
  • PHP Spaceship Operator
  • AND Operator
  • Exclusive OR
  • Spread Operator
  • Elvis 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

Examples: String and Patterns

  • Remove the Last Char

Other Tutorials

  • require_once & require
  • array_map()

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 Classes: A Comprehensive Guide for Software Developers
  • Understanding PHP Abstract Classes
  • Understanding PHP Cookies
  • The Ultimate Guide to PHP Directory
  • PHP Math: 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 FIle Open Read

PHP File Open Read

PHP File Open Read As a software developer, I’ve come to appreciate the importance of file handling in programming. PHP, a server-side scripting language, has its own file handling functions that allow us to work with files on the server. One of the most commonly used file handling functions in PHP is the “file open…

PHP Static Properties

PHP Static Properties: Exploring the Benefits and Use Cases

As a software developer, understanding the benefits and use cases of PHP static properties can greatly improve your coding efficiency and help you create more effective and optimized software. In this article, we’re going to dive deep into PHP static properties – what they are, how they work, and how you can use them to…

PHP Comments

PHP Comments: A Comprehensive Guide

As a PHP developer, you are always writing code. Writing code is a creative and challenging process that requires a lot of attention to detail. In addition to writing code, you also need to write comments that explain what the code does. Comments are essential in any programming language, and PHP is no exception. In…

PHP Form Validation

PHP Form Validation

Form validation is an essential part of web development. It helps ensure that the data submitted through web forms is accurate and meets the expected format, leading to a more secure and better user experience. This article will discuss PHP form validation, its importance, and how to implement it in your web applications. Why is…

PHP Arrays

Understanding PHP Arrays: A Comprehensive Guide

Arrays are one of the essential data structures in programming, and PHP arrays are no exception. In PHP, arrays store and manipulate multiple values, which can be of different data types. PHP arrays are a versatile and powerful feature that enables developers to work with complex data structures efficiently. This article will cover the basics…

the history of php

The Surprising History of PHP: From Challenge to Competitive Advantage

The Origins of PHP: Personal Home Pages PHP (Hypertext Preprocessor) is a server-side scripting language initially created by Rasmus Lerdorf in 1994. The language was originally designed to help Lerdorf manage his personal website, which consisted of a few basic scripts written in C. The first version of PHP was called Personal Home Page Tools…

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 Tutorial

  • PHP Tutorial
  • PHP - Introduction
  • PHP - Installation
  • PHP - History
  • PHP - Features
  • 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 - Loop Types
  • 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 - Quick Guide
  • 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 −

Operator Description Example
= Simple assignment operator. Assigns values from right side operands to left side operand C = A + B will assign value of A + B into C
+= Add AND assignment operator. It adds right operand to the left operand and assign the result to left operand C += A is equivalent to C = C + A
-= Subtract AND assignment operator. It subtracts right operand from the left operand and assign the result to left operand C -= A is equivalent to C = C - A
*= Multiply AND assignment operator. It multiplies right operand with the left operand and assign the result to left operand C *= A is equivalent to C = C * A
/= Divide AND assignment operator. It divides left operand with the right operand and assign the result to left operand C /= A is equivalent to C = C / A
%= Modulus AND assignment operator. It takes modulus using two operands and assign the result to left operand C %= A is equivalent to C = C % A

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

It will produce the following output −

  • ▼PHP Operators
  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Assignment Operators
  • Bitwise Operators
  • String Operators
  • Array Operators
  • Incrementing Decrementing Operators

PHP Assignment Operators

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. In addition to the regular assignment operator "=", several other assignment operators are composites of an operator followed by an equal sign.

Interestingly all five arithmetic operators have corresponding assignment operators, Here is the list.

The following table discussed more details of the said assignment operators.

Shorthand Expression Description
$a+= $b $a = $a + $b Adds 2 numbers and assigns the result to the first.
$a-= $b $a = $a -$b Subtracts 2 numbers and assigns the result to the first.
$a*= $b $a = $a*$b Multiplies 2 numbers and assigns the result to the first.
$a/= $b $a = $a/$b Divides 2 numbers and assigns the result to the first.
$a%= $b $a = $a%$b Computes the modulus of 2 numbers and assigns the result to the first.

View the example in the browser

Previous: Logical Operators Next: Bitwise Operators

Follow us on Facebook and Twitter for latest update.

  • Weekly Trends and Language Statistics

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:

OperatorNameDescription
+AdditionReturn the sum of two operands
SubtractionReturn the difference between two operands
*MultiplicationReturn the product of two operands
/DivisionReturn the quotient of two operands
%ModulusReturn the remainder of the division of the first operand by the second one

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:

OperatorNameDescription
==EqualityReturn if both operands are equal, otherwise returns .
===IdentityReturn if both operands have the same data type and equal, otherwise return .
!===Not identicalReturn if both operands are not equal or not have the same data type, otherwise return .
>Greater thanReturn if the operand on the left  is greater than the operand on the right, otherwise return .
>=Greater than or equal toReturn if the operand on the left  is greater than or equal to the operand on the right, otherwise return .
<Less thanReturn if the operand on the left is less than the operand on the right, otherwise return .
<=Less than or equalReturn if the operand on the left  is less than or equal to the operand on the right, otherwise return .

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

PHP provides the following logical operators:

OperatorNameDescription
&&Logical ANDReturn if both operands are , otherwise return . If the first operand is , it will not evaluate the second operand because it knows for sure that the result is going to be . This is known as short-circuiting.
||Logical ORReturn if one of the operands is , otherwise returns . If the first operand is , it will not evaluate the second one.
xorLogical XORReturn if either operand, not both, is otherwise, return
!Notreturns if the operand is and returns if the operand is .

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

OperatorsNameResult
AndIf both bits are 1, the corresponding bit in the result is 1; otherwise, the corresponding bit is 0
Or (inclusive or)If both bits are 0, the corresponding bit in the result is 0; otherwise, the corresponding bit is 1
Xor (exclusive or)If either bit, but not both, in  and  are 1, the corresponding bit in the result is 1; otherwise, the corresponding bit is 0
NotChange bit 1 to 0 and 0 to 1 in the $x operand
Shift leftShifts the bits in left by the number of places specified by .
Shift rightShifts the bits in  right by the number of places specified by .

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:

ExampleNameReturned ValueEffect on $a
Pre-increment Increments  by 1, then returns .
Post-increment Returns , then increments  by 1.
Pre-decrement Decrements  by 1, then returns .
Post-decrement Returns , then decrements  by 1.

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.

  • Language Reference

String Operators

There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator (' .= '), which appends the argument on the right side to the argument on the left side. Please read Assignment Operators for more information.

<?php $a = "Hello " ; $b = $a . "World!" ; // now $b contains "Hello World!" $a = "Hello " ; $a .= "World!" ; // now $a contains "Hello World!" ?>

  • String type
  • String functions

Improve This Page

User contributed notes 6 notes.

To Top

  • PHP Tutorial
  • PHP Exercises
  • 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 Operators

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.

+

Addition

$x + $y

Sum the operands

Subtraction

$x – $y

Differences the operands

*

Multiplication

$x * $y

Product of the operands

/

Division

$x / $y

The quotient of the operands

**

Exponentiation

$x ** $y

$x raised to the power $y

%

Modulus

$x % $y

The remainder of the operands

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.

andLogical AND$x and $yTrue if both the operands are true else false
orLogical OR$x or $yTrue if either of the operands is true else false
xorLogical XOR$x xor $yTrue if either of the operands is true and false if both are true
&&Logical AND$x && $yTrue if both the operands are true else false
||Logical OR$x || $yTrue if either of the operands is true else false
!Logical NOT!$xTrue if $x is false

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.

OperatorNameSyntaxOperation
==Equal To$x == $yReturns True if both the operands are equal
!=Not Equal To$x != $yReturns True if both the operands are not equal
<>Not Equal To$x <> $yReturns True if both the operands are unequal
===Identical$x === $yReturns True if both the operands are equal and are of the same type
!==Not Identical$x == $yReturns True if both the operands are unequal and are of different types
<Less Than$x < $yReturns True if $x is less than $y
>Greater Than$x > $yReturns True if $x is greater than $y
<=Less Than or Equal To$x <= $yReturns True if $x is less than or equal to $y
>=Greater Than or Equal To$x >= $yReturns True if $x is greater than or equal to $y

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.

?:

Ternary

If the condition is true? then $x : or else $y. This means that if the condition is true then the left result of the colon is accepted otherwise the result is on right.

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.

=

Assign

$x = $y

Operand on the left obtains the value of the operand on the right

+=

Add then Assign

$x += $y

Simple Addition same as $x = $x + $y

-=

Subtract then Assign

$x -= $y

Simple subtraction same as $x = $x – $y

*=

Multiply then Assign

$x *= $y

Simple product same as $x = $x * $y

/=

Divide then Assign (quotient)

$x /= $y

Simple division same as $x = $x / $y

%=

Divide then Assign (remainder)

$x %= $y

Simple division same as $x = $x % $y

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.

+

Union

$x + $y

Union of both i.e., $x and $y

==

Equality

$x == $y

Returns true if both has same key-value pair

!=

Inequality

$x != $y

Returns True if both are unequal

===

Identity

$x === $y

Returns True if both have the same key-value pair in the same order and of the same type

!==

Non-Identity

$x !== $y

Returns True if both are not identical to each other

<>

Inequality

$x <> $y

Returns True if both are unequal

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.

++Pre-Increment++$xFirst increments $x by one, then return $x
Pre-Decrement–$xFirst decrements $x by one, then return $x
++Post-Increment$x++First returns $x, then increment it by one
Post-Decrement$x–First returns $x, then decrement it by one

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.

.Concatenation$x.$yConcatenated $x and $y
.=Concatenation and assignment$x.=$yFirst concatenates then assigns, same as $x = $x.$y

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:

$x < $y$x <=> $yIdentical to -1 (right is greater)
$x > $y$x <=> $yIdentical to 1 (left is greater)
$x <= $y$x <=> $yIdentical to -1 (right is greater) or identical to 0 (if both are equal)
$x >= $y$x <=> $yIdentical to 1 (if left is greater) or identical to 0 (if both are equal)
$x == $y$x <=> $yIdentical to 0 (both are equal)
$x != $y$x <=> $yNot Identical to 0

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

Please Login to comment...

Similar reads.

  • Web Technologies
  • PHP-Operators
  • Discord Emojis List 2024: Copy and Paste
  • Best Adblockers for Twitch TV: Enjoy Ad-Free Streaming in 2024
  • PS4 vs. PS5: Which PlayStation Should You Buy in 2024?
  • Best Mobile Game Controllers in 2024: Top Picks for iPhone and Android
  • 15 Most Important Aptitude Topics For Placements [2024]

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

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.

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

Sample usage of Arithmetic Operators:

Assignment Operators

Assignment operators are used to assign values to variables.

Operator Name Example Output
Assign $x = $y The left operand gets set to the value of the expression on the right
Add and assign $x += $y Addition
Subtract and assign $x -= $y Subtraction
Multiply and assign $x *= $y Multiplication
Divide and assign quotient $x /= $y Division
Divide and assign modulus Modulus

Sample usage of Assignment Operators:

Comparison Operators

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

Operator Name Example Output
Equal $x == $y True if is equal to
Identical $x === $y True if is equal to , and they are of the same type
Not equal $x != $y True if is not equal to
Not equal $x <> $y True if is not equal to
Not identical $x !== $y True if is not equal to , or they are not of the same type
Less than $x < $y True if is less than
Greater than $x > $y True if is greater than
Greater than or equal to $x >= $y True if is greater than or equal to
Less than or equal to $x <= $y True if is less than or equal to

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.

Operator Name Output
Pre-increment Increments by one, then returns
Post-increment Returns , then increments by one
Pre-decrement Decrements by one, then returns
Post-decrement Returns , then decrements by one

Sample usage of Increment / Decrement Operators:

Logical Operators

Logical operators are typically used to combine conditional statements.

Operator Name Example Output
And $x and $y if both and are
Or $x or $y if either or is
Xor $x xor $y if either or is , but not both
And $x && $y if both and are
` ` Or
Not !$x if is not

Sample usage of Logical Operators:

String Operators

String operators are specifically designed for strings.

Operator Name Example Output
Concatenation $str1 . $str2 Concatenation of and
Concatenation assignment $str1 .= $str2 Appends the to the

Sample usage of String Operators:

Array Operators

Array operators are used to compare arrays.

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

Conditional Assignment Operators

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

Operator Name Example Output
Ternary $x = expr1 ? expr2 : expr3 Returns the value of . The value of is expr2 if expr1 = . The value of is expr3 if expr1 =
Null coalescing $x = expr1 ?? expr2 Returns the value of . The value of is expr1 if expr1 exists, and is not . If expr1 does not exist, or is , the value of is expr2. Introduced in PHP 7

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

PHP Operators

In this tutorial you will learn how to manipulate or perform the operations on variables and values using operators in PHP.

What is Operators in PHP

Operators are symbols that tell the PHP processor to perform certain actions. For example, the addition ( + ) symbol is an operator that tells PHP to add two variables or values, while the greater-than ( > ) symbol is an operator that tells PHP to compare two values.

The following lists describe the different operators used in PHP.

PHP Arithmetic Operators

The arithmetic operators are used to perform common arithmetical operations, such as addition, subtraction, multiplication etc. Here's a complete list of PHP's arithmetic operators:

Operator Description Example Result
Addition Sum of $x and $y
Subtraction Difference of $x and $y.
Multiplication Product of $x and $y.
Division Quotient of $x and $y
Modulus Remainder of $x divided by $y

The following example will show you these arithmetic operators in action:

PHP Assignment Operators

The assignment operators are used to assign values to variables.

Operator Description Example Is The Same As
Assign
Add and assign
Subtract and assign
Multiply and assign
Divide and assign quotient
Divide and assign modulus

The following example will show you these assignment operators in action:

PHP Comparison Operators

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

Operator Name Example Result
Equal True if $x is equal to $y
Identical True if $x is equal to $y, and they are of the same type
Not equal True if $x is not equal to $y
Not equal True if $x is not equal to $y
Not identical True if $x is not equal to $y, or they are not of the same type
Less than True if $x is less than $y
Greater than True if $x is greater than $y
Greater than or equal to True if $x is greater than or equal to $y
Less than or equal to True if $x is less than or equal to $y

The following example will show you these comparison operators in action:

PHP Incrementing and Decrementing Operators

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

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

The following example will show you these increment and decrement operators in action:

PHP Logical Operators

The logical operators are typically used to combine conditional statements.

Operator Name Example Result
And True if both $x and $y are true
Or True if either $x or $y is true
Xor True if either $x or $y is true, but not both
And True if both $x and $y are true
Or True if either $x or $y is true
Not True if $x is not true

The following example will show you these logical operators in action:

PHP String Operators

There are two operators which are specifically designed for strings .

Operator Description Example Result
Concatenation Concatenation of $str1 and $str2
Concatenation assignment Appends the $str2 to the $str1

The following example will show you these string operators in action:

PHP Array Operators

The array operators are used to compare arrays:

Operator Name Example Result
Union Union of $x and $y
Equality True if $x and $y have the same key/value pairs
Identity True if $x and $y have the same key/value pairs in the same order and of the same types
Inequality True if $x is not equal to $y
Inequality True if $x is not equal to $y
Non-identity True if $x is not identical to $y

The following example will show you these array operators in action:

PHP Spaceship Operator PHP 7

PHP 7 introduces a new spaceship operator ( <=> ) which can be used for comparing two expressions. It is also known as combined comparison operator.

The spaceship operator returns 0 if both operands are equal, 1 if the left is greater, and -1 if the right is greater. It basically provides three-way comparison as shown in the following table:

Operator Equivalent

The following example will show you how spaceship operator actually works:

Bootstrap UI Design Templates

Is this website helpful to you? Please give us a like , or share your feedback to help us improve . Connect with us on Facebook and Twitter for the latest updates.

Interactive Tools

BMC

PHP Operators

Php tutorial index.

PHP operators are characters or sets of characters used to manipulate or perform operations on expressions and values.

Operators allow you to perform arithmetic operations, assign values to variables, string concatenation, compare deals, and perform boolean operations.

Types of Operators in PHP

  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Ternary Operator
  • Concatenation Operators
  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Boolean assignment operators in PHP

I find myself doing this kind of thing somewhat often:

With bitwise operators, you can use the &= and |= shorthand:

Given that bitwise operations on 1 and 0 are functionally equivalent to boolean operations on true and false , we can rely on type-casting and do something like this:

...but that's pretty ugly and defeats the purpose of using a shorthand assignment syntax, since we have to use another statement to get the type back to boolean.

What I'd really like to do is something like this:

...but &&= and ||= are not valid operators, obviously. So, my question is - is there some other sugary syntax or maybe an obscure core function that might serve as a stand-in? With variables as short as $foo , it's not a big deal to just use $foo = $foo && false syntax, but array elements with multiple dimensions, and/or object method calls can make the syntax quite lengthy.

  • boolean-logic
  • syntactic-sugar

FtDRbwLXw6's user avatar

  • What is wrong with $foo = $foo && false;? Or is it just curiosity? –  Dany Caissy Commented Jul 9, 2013 at 16:08
  • 2 @DanyCaissy: I explained in the last paragraph. There's nothing wrong with it; it's just that that syntax is redundant, and can get very lengthy (e.g. $some['big']['long']['variable'] = $some['big']['long']['variable'] && $some['other']['boolean']; ). –  FtDRbwLXw6 Commented Jul 9, 2013 at 16:10
  • You may want to change your examples. Logically, these will always yield the same result = $foo &= false; and $foo &&= false; for $foo = true . So I'm failing to see the problem/goal. –  Jason McCreary Commented Jul 9, 2013 at 16:19
  • 2 @JasonMcCreary: It depends on your definition of "same." As my examples point out, the former yields int(0) and the latter yields bool(false) . So while 0 == false because of implicit type-casting, 0 !== false . –  FtDRbwLXw6 Commented Jul 9, 2013 at 16:50
  • This is still relevent 7 years latter with PHP7/8 type enforcement checks. Very easy to accidentally convert from a bool to an int if you use short syntax. –  evo_rob Commented Apr 6, 2021 at 11:26

3 Answers 3

In a way you have answered your own question:

bitwise operations on 1 and 0 are functionally equivalent to boolean operations on true and false

Bearing in mind that PHP is a weakly typed language, so it is not necessary to typecast to and from strict boolean values as 1 and 0 are equivalent to true and false (except strict equality, see below).

Consider the following code, using your examples:

Given PHP's implicit type juggling , falsy values , and with the exception of strict equaltiy , I'm hard pressed to see where such shorthand operations of &&= and ||= would not yield the same result as &= and |= . Especially when evaluating boolean values . It's likely why such shorthands don't exist in PHP.

Some quick benchmarks prove these are indeed equivalent, except for truthy arrays/objects:

Jason McCreary's user avatar

  • 1 You're correct, but I was actually looking for a solution that didn't change the type (hence why my 3rd example was explicitly type-casting back into a bool ). I have control over both the operands, and they're guaranteed to be bool s, so I'd much rather just use the longer syntax than potentially introduce errors into the code by returning "falsy" values instead of a strict bool like the interface has documented. –  FtDRbwLXw6 Commented Jul 9, 2013 at 17:00
  • 1 Fair. Even though PHP is a weakly typed, dynamic language, I support writing such explicit code. My answer is based on that fact that for boolean values (and most other simple types) bitwise operators are equivalent to boolean operators. But if you want to use such a shorthand, you have to give up strict equality checks (or compare to 0/1). In the end, I don't really see the point. Nonetheless, I wanted to provide an answer for future readers. –  Jason McCreary Commented Jul 9, 2013 at 17:24
  • Keep in mind, you could always cast it before returning the value. Probably good practice anyway. –  Jason McCreary Commented Jul 9, 2013 at 17:45
  • 1 @JasonMcCreary No, boolean and bitwise operators are not equivalent, though their output is. The big difference is, that PHP does not even execute an expression for boolean operates if the outcome makes no difference. So $res = sql_query() OR die(); is not equivalent to $res = sql_query(); $res |= die(); . –  Matteo B. Commented Mar 25, 2015 at 11:45
  • 1 @Matmarbon, correct, in these comments I forgot a key qualifier - functionally equivalent. –  Jason McCreary Commented Mar 25, 2015 at 12:57

As Jason mentioned, bitwise operators will work and it will not be necessary to convert the result back to boolean, as PHP will already handle their value as a boolean properly.

If you want an alternative that does not use bitwise operators, for the sake of readability or if you want strict equality, you can use this method :

Which means, you could change this :

It would also work with multiple conditions :

Dany Caissy's user avatar

  • 2 While helpful, it seems the OP is looking for something native and aware they can write custom code. –  Jason McCreary Commented Jul 9, 2013 at 16:22
  • 1 I don't think there is something native that would do it for them, this is why I put this here. I'll remove my answer if I am proven wrong. While I'm sure OP could have came up with this method by himself, future readers that are less experienced might find it useful. –  Dany Caissy Commented Jul 9, 2013 at 16:23
  • Did someone thing to post this to the PHP dev team? –  theking2 Commented Apr 6, 2022 at 12:00
  • I did: on github –  theking2 Commented Apr 6, 2022 at 12:09

Right, &&= and ||= operators are indeed missing in PHP because bitwise operators can not be used as a replacement (without casting).

Here is an example you would expect to return true but returns false :

The missing &&= operator would return true because 1 && 10 = true

Christopher Pereira's user avatar

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged php syntax boolean-logic syntactic-sugar or ask your own question .

  • The Overflow Blog
  • The hidden cost of speed
  • The creator of Jenkins discusses CI/CD and balancing business with open source
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • How should I tell my manager that he could delay my retirement with a raise?
  • Fusion September 2024: Where are we with respect to "engineering break even"?
  • Humans are forbidden from using complex computers. But what defines a complex computer?
  • Remove an edge from the Hasse diagram of a finite lattice
  • How does the phrase "a longe" meaning "from far away" make sense syntactically? Shouldn't it be "a longo"?
  • Geometry nodes: spline random
  • Is there a non-semistable simple sheaf?
  • Are there alternative methods, beyond Bayesian or probabilistic approaches, for modeling the relationship between evidence and hypothesis credibility?
  • Manhattan distance
  • Why does Jeff think that having a story at all seems gross?
  • Is there a problem known to have no fastest algorithm, up to polynomials?
  • Replacing jockey wheels on Shimano Deore rear derailleur
  • "Mixture, Pitch then Power" - why?
  • Questions about LWE in NIST standards
  • What is this movie aircraft?
  • Can I use Cat 6A to create a USB B 3.0 Superspeed?
  • Current in a circuit is 50% lower than predicted by Kirchhoff's law
  • How can I play MechWarrior 2?
  • Representing permutation groups as equivalence relations
  • Romeo & Juliet laws and age of consent laws
  • How to connect 20 plus external hard drives to a computer?
  • how did the Apollo 11 know its precise gyroscopic position?
  • Breaker trips when plugging into wall outlet(receptacle) directly, but not when using extension
  • Visual assessment of scatterplots acceptable?

php or assignment operator

  • Today's news
  • Reviews and deals
  • Climate change
  • 2024 election
  • Newsletters
  • Fall allergies
  • Health news
  • Mental health
  • Sexual health
  • Family health
  • So mini ways
  • Unapologetically
  • Buying guides
  • Labor Day sales

Entertainment

  • How to Watch
  • My watchlist
  • Stock market
  • Biden economy
  • Personal finance
  • Stocks: most active
  • Stocks: gainers
  • Stocks: losers
  • Trending tickers
  • World indices
  • US Treasury bonds
  • Top mutual funds
  • Highest open interest
  • Highest implied volatility
  • Currency converter
  • Basic materials
  • Communication services
  • Consumer cyclical
  • Consumer defensive
  • Financial services
  • Industrials
  • Real estate
  • Mutual funds
  • Credit cards
  • Balance transfer cards
  • Cash back cards
  • Rewards cards
  • Travel cards
  • Online checking
  • High-yield savings
  • Money market
  • Home equity loan
  • Personal loans
  • Student loans
  • Options pit
  • Fantasy football
  • Pro Pick 'Em
  • College Pick 'Em
  • Fantasy baseball
  • Fantasy hockey
  • Fantasy basketball
  • Download the app
  • Daily fantasy
  • Scores and schedules
  • GameChannel
  • World Baseball Classic
  • Premier League
  • CONCACAF League
  • Champions League
  • Motorsports
  • Horse racing

New on Yahoo

  • Privacy Dashboard

Motorcycle operator killed in Ellerslie crash

Sep. 7—ELLERSLIE — A West Virginia motorcyclist died Thursday following an accident in the 14000 block of Ellerslie Road, the Allegany County Sheriff's Office said.

Robert Jeffrey Palmer, 63, of Paw Paw, was driving the motorcycle north when he crossed the center line and struck a southbound sport utility vehicle, the sheriff's office said.

The SUV driver, who was not identified, was taken to UPMC Western Maryland for treatment of minor injuries.

The accident remains under investigation, the sheriff's office said.

The sheriff's office also was investigating a Wednesday night crash on Legislative Road in the Barton area. Additional information about that accident was not available.

php or assignment operator

Press Herald

Account Subscription: ACTIVE

Questions about your account? Our customer service team can be reached at [email protected] during business hours at (207) 791-6000 .

  • Boston Red Sox

Red Sox designate veteran pitcher Rich Hill for assignment

The Red Sox bring up right-hander Luis Guerrero to bolster the bullpen.

Resize Font

You are able to gift 5 more articles this month.

Anyone can access the link you share with no account required. Learn more .

With a Press Herald subscription, you can gift 5 articles each month.

It looks like you do not have any active subscriptions. To get one, go to the subscriptions page .

Loading....

php or assignment operator

The Boston Red Sox designated pitcher Rich Hill for assignment on Friday. Hill, who signed with the team in August, made four relief appearances and had an ERA of 4.91. Noah K. Murray/Associated Press

BOSTON — One of the feel-good stories of the Boston Red Sox season didn’t last long.

Rich Hill, who returned to the team recently at age 44, was designated for assignment Friday. In Hill’s place, the Red Sox added right-hander Luis Guerrero to their active roster.

Hill, who sat out the first half of the season to coach his son’s Little League team, signed a minor league deal with the Red Sox in mid-August and was promoted to the big leagues soon after.

Hill made four appearances with the Red Sox, all in relief, compiling a 4.91 ERA. His last appearance came earlier this week when he entered a game at Citi Field against the New York Mets and issued two walks in 1/3 inning.

Guerrero, 24, had a 3.31 ERA at Worcester while holding batters to a .198 average. He averaged 13.09 strikeouts per nine innings over 42 game for the WooSox. A native of the Dominican Republic, Guerrero moved to Boston as a child. He was a 17th-round pick by the Red Sox in 2021.

It’s unknown whether Hill intends to continue his career. He’s pitched in 20 seasons, compiling a lifetime mark of 90-74 with a 4.01 ERA. Advertisement

Drafted in 2002, Hill has played for 13 organizations including some, like the Red Sox, several times. He pitched for the Sox in 2010, 2011, 2012, 2015, 2022 and again this season.

“It’s more about Guerrero than anything else,” said Manager Alex Cora. “With Rich, obviously, tough one. Everybody feels for him, everyone in the organization. He’s going to be a Red Sox for life. But I think it’s smart for us to start getting guys here that can contribute now and obviously in the future.”

Cora noted that Hill struggled with control, with three walks in 3 2/3 innings.

“He looked good in the first (outing) here,” said Cora. “Then the (Kerry) Carpenter at-bat was a good one and he gave up the homer (in Detroit). The last one (in New York), he wasn’t able to throw strikes.”

BREWERS: Minor league pitcher Ever Urena was suspended for 56 games following a positive test for the performance-enhancing substance Stanozolol under baseball’s drug program for players assigned outside the U.S. and Canada.

A 19-year-old right-hander, Urena agreed to a minor league contract with the Brewers in July had a 0.00 ERA and one save in six games and 5 1/3 innings in the Dominican Summer League. Advertisement

RANGERS: Elvis Andrus signed a ceremonial one-day contract to officially retire with Texas, the team he played for in the first 12 of his 15 seasons in the majors.

Andrus made his big-league debut as a 20-year-old shortstop in 2009 and was a steady presence up the middle when the Rangers went to back-to-back World Series in 2010-11. He was also part of AL West-winning teams in 2015-16.

PHILLIES: Philadelphia placed third baseman Alex Bohm on the 10-day injured list because of a left hand strain.

Bohm hurt his hand Aug. 29 while taking a swing in the game against Atlanta. He remained with the club, hoping for a quick recovery. But Bohm didn’t heal sufficiently, forcing the Phillies to remove him from the active roster.

• Catcher J.T. Realmuto left in the fourth inning against Miami, two innings after fouling a pitch off his left knee.

DODGERS: Los Angeles placed pitcher Gavin Stone on the injured list, and it’s uncertain whether he will return this season. Advertisement

Stone was the last Dodgers starter who had been healthy all season. Now he has right shoulder inflammation. He won’t throw for 10 to 14 days before attempting to ramp back up with less than a month left in the regular season, Manager Dave Roberts said.

DIAMONDBACKS: Catcher Jose Herrera left the game at Houston after Kyle Tucker struck him on top of the head on a follow-through in the fifth inning.

Tucker struck out swinging, with his bat hitting Herrera on the top of his helmet. Herrera crumpled to the ground, and Manager Torey Lovullo and a trainer immediately raced to the plate.

FRIDAY’S GAMES

YANKEES 3, CUBS 0: Luis Gil pitched six sparkling innings in his return from a back injury, and New York won at Chicago.

Aaron Judge hit an RBI double and scored on Austin Wells’ two-run single as New York scored three times in the third inning in its first game at Wrigley Field since 2017. Judge went 1 for 3 with a walk in his 10th straight game without a home run – his longest streak of the season. Advertisement

ROCKIES 3, BREWERS 2: Michael Toglia hit a three-run home run, Ryan Feltner struck out six over six innings of one-run ball at Milwaukee and Colorado won consecutive games for the first time since early August.

Feltner (2-10) held Milwaukee to a pair of hits while walking three for his first victory since April 10. The only blemish came in the third when Jake Bauers walked and scored on a base hit by Joey Ortiz.

ORIOLES 2, RAYS 0: Dean Kremer took a no-hitter into the seventh inning, Gunnar Henderson hit his 36th home run and Baltimore won at home to remain atop the AL East.

Kremer lost his no-hit bid when rookie Junior Caminero led off the seventh with a sharp single to left field. Dylan Carlson then grounded a single to right. After Josh Lowe reached on an error to load the bases with no outs, Kremer was pulled by Manager Brandon Hyde with Baltimore nursing a 2-0 lead.

BRAVES 3, BLUE JAYS 1: Max Fried pitched seven strong innings and Atlanta won at home.

Fried (9-8) had command of the plate all night, striking out eight and allowing just five hits. Toronto’s lone run was unearned, coming in the third inning on an Atlanta error. Advertisement

PHILLIES 16, MARLINS 2: Trea Turner was a triple shy of the cycle, Kyle Schwarber hit his 33rd homer and Bryce Harper had three hits to help Philadelphia win at Miami.

Johan Rojas added three doubles, and Kody Clemens also had three hits for the Phillies.

METS 6, REDS 4: Mark Vientos hit a pair of two-run homers, including a leadoff shot in the 10th inning that sent New York to a win at home for its eighth consecutive victory.

New York is riding its longest winning streak since an eight-game run in August 2019. Vientos also connected in the first inning for the Mets, who remained tied with Atlanta for the last National League wild card.

ROYALS 5, TWINS 0: Cole Ragans scattered four hits in six scoreless innings as the Kansas City won at home and traded places with Minnesota in the AL Central and wild-card standings.

The Royals now hold a half-game lead for second place in the division and the second wild-card spot.

ANGELS 5, RANGERS 1: Italian rookie Sam Aldegheri won for the first time in the major leagues, allowing a run on three hits in six innings for Los Angeles at Arlington, Texas.

Aldegheri (1-1), the first major league pitcher born and raised in Italy, struck out seven and walked three in his second career start. Last Friday night, the 22-year-old left-hander gave up seven runs – two earned – in five innings in a 9-5 loss to Seattle.

We invite you to add your comments, and we encourage a thoughtful, open and lively exchange of ideas and information on this website. By joining the conversation, you are agreeing to our commenting policy and terms of use . You can also read our FAQs . You can modify your screen name here .

Readers may now see a Top Comments tab, which is an experimental software feature to detect and highlight comments that demonstrate compassion, reasoning, personal stories and curiosity, and encourage and promote civil discourse.

Join the Conversation

Please sign into your Press Herald account to participate in conversations below. If you do not have an account, you can register or subscribe . Questions? Please see our FAQs .

Your commenting screen name has been updated.

Send questions/comments to the editors.

« Previous

First-inning grand slam sends Red Sox to fifth straight loss

Next »

Red Sox snap five-game losing streak with win over White Sox

Virginia woman found dead in Dayton had just moved to Maine

No rivalry here: twin brothers behind 2 portland bbq joints are each other’s wingman, portland considers reverting high and state streets to two-way traffic, south portland plans $74 million renovation of mahoney middle. residents ask if it’s needed., grassroots group’s report sharply criticizes gorham connector proposal, member log in.

Please enter your username and password below. Already a subscriber but don't have one? Click here .

Not a subscriber? Click here to see your options

IMAGES

  1. PHP operators Tutorial Example

    php or assignment operator

  2. PHP ASSIGNMENT OPERATORS

    php or assignment operator

  3. Complete Guide and Tutorials for PHP Operators with example

    php or assignment operator

  4. Assignment Operators in PHP

    php or assignment operator

  5. Complete Guide and Tutorials for PHP Operators with example

    php or assignment operator

  6. PHP Assignment Operators

    php or assignment operator

VIDEO

  1. PHP Assignment/Project 4

  2. PHP Assignment-3

  3. php operators, assignment operators

  4. 3 Operators in PHP

  5. #8 [Логические операторы и операторы сравнения в PHP]

  6. 08

COMMENTS

  1. PHP: Assignment

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world. ... 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 ...

  2. PHP Operators

    PHP Operators - W3Schools ... PHP Operators

  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. PHP: Operators

    Operators - Manual

  5. 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

  6. 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.

  7. 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.

  8. Mastering Assignment Operators in PHP: A Comprehensive Guide

    Assignment operators are foundational to PHP programming, allowing developers to initialize, update, and manipulate variables efficiently. From the basic = operator to combined assignment operators like += and .=, understanding their proper use is crucial for writing clear and effective code. Encouragement to practice using different types of ...

  9. 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 ...

  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 Operators: Understanding the Building Blocks of PHP Programming

    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 ...

  12. PHP

    PHP - Assignment Operators Examples

  13. PHP assignment operators

    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. In addition to the regular assignment operator "=", several other assignment operators are composites of an ...

  14. 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.

  15. 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.

  16. PHP: String

    There are two string operators. The first is the concatenation operator ('.'), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator ('.= '), which appends the argument on the right side to the argument on the left side. Please read Assignment Operators for more information.

  17. PHP Operators

    In PHP, the '=' operator is used for assignment, while the '==' operator is used for loose equality comparison, meaning it checks if two values are equal without considering their data types. On the other hand, the '===' operator is used for strict equality comparison, meaning it checks if two values are equal and of the same data type. = OperatorT

  18. 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

  19. Working with PHP Operators

    Operators are symbols that tell the PHP processor to perform certain actions. For example, the addition (+) symbol is an operator that tells PHP to add two variables or values, while the greater-than (>) symbol is an operator that tells PHP to compare two values. The following lists describe the different operators used in PHP.

  20. PHP: Assignment

    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: ... An exception to the usual assignment by value behaviour within PHP occurs with ...

  21. PHP Operators

    Boost your understanding of PHP operators with our comprehensive tutorials. Discover the types of operators in PHP, including arithmetic, assignment, comparison, logical, ternary, and concatenation operators.

  22. syntax

    Fair. Even though PHP is a weakly typed, dynamic language, I support writing such explicit code. My answer is based on that fact that for boolean values (and most other simple types) bitwise operators are equivalent to boolean operators. But if you want to use such a shorthand, you have to give up strict equality checks (or compare to 0/1).

  23. Motorcycle operator killed in Ellerslie crash

    Sep. 7—ELLERSLIE — A West Virginia motorcyclist died Thursday following an accident in the 14000 block of Ellerslie Road, the Allegany County Sheriff's Office said. Robert Jeffrey Palmer, 63, of Paw Paw, was driving the motorcycle north when he crossed the center line and struck a southbound sport utility vehicle, the sheriff's office said. The SUV driver, who was not identified, was taken ...

  24. Red Sox designate veteran pitcher Rich Hill for assignment

    The Boston Red Sox designated pitcher Rich Hill for assignment on Friday. Hill, who signed with the team in August, made four relief appearances and had an ERA of 4.91. Noah K. Murray/Associated Press