What's this?
This is a collection of questions that arise from time to time about PHP syntax. This is also a community wiki, so everyone is invited to participate in maintaining this list.
why is that?
It used to be difficult to find questions about operators and other syntax markers. ¹
The main idea is to provide links to existing questions on Stack Overflow so that we can refer to them more easily instead of copying content from the PHP manual.
Note: As of January 2013, Stack Overflow supports special characters. Just enclose your search term in quotes, like[php]"==" vs. "==="
What should I do here?
If you were pointed here by someone because you asked a question like this, look for the specific syntax below. The linked page of the PHP manual and the linked question may answer your question. If so, we encourage you to vote for the answer. This list is not a substitute for help from others.
List
If your specific token is not listed below, you may find it in the parser token list.
&
Bit operators or references
- What does it mean to start a PHP function with & symbol?
- Understand the PHP & (ampersand, bitwise AND) operator
- PHP “&” Operator
- The difference between & and && in PHP
- What does "&" mean in PHP?
- What does "&" mean in this case?
- What does the "&" symbol mean in PHP?
- What does this signature (&) mean in PHP?
- How does the "&" operator work in PHP functions?
- &2 What does the & in PHP mean?
- When should you use bitwise operators?
- Do I need to use the ampersand in front of the object? (&$)
=&
References
- Quoting the assignment operator in PHP =&
- What do the "=&" and "&=" operators in PHP mean?
- What do the "&=" and "=&" operators do?
What does
- =& mean in PHP?
&=
Bit operators
- What do the "=&" and "&=" operators in PHP mean?
- What do the "&=" and "=&" operators do?
&&
Logical Operators
- "AND" and "&&" as operators
- The difference between & and && in PHP
- Is there any difference between the "and" and "&&" operators in PHP?
- PHP - and/or keywords
%
Arithmetic operators
- What does the percent sign mean in PHP?
- What is the PHP operator % and how to use it in real examples?
!!
Logical Operators
- Double NOT (!!) operator in PHP
@
Error control operator
What is the use of the
- @ symbol in PHP?
- The "At" symbol before the variable name in PHP: @$_POST
- PHP functions and @functions
- Should I use @ in PHP code?
What does
- @ mean in PHP?
?:
Ternary operator
- What are the PHP operators "?" and ":" calls and what do they do?
- ?: Operators in PHP ("Elvis operators")
- Where can I read information about conditions completed with "?" and ":" (colon)?
- Using PHP 5.3 ?: operator
Double question mark
??
Null coalescing operator (since PHP 7)
- Null coalescing operator (??) for C# in PHP
Question mark followed by type declaration
?string
?int
?array
?bool
?float
Nullable type declaration (since PHP 7.1)
- How to use nullable types
- Nullable return type declaration
?->
A question mark followed by an object operator is the NullSafe operator (since PHP 8.0)
- Is there a "nullsafe operator" in PHP?
:
Alternative syntax for control structures, ternary operators, and return type declarations
- What is ":" in PHP?
- What does ":" mean in PHP?
- Colon after method declaration?
::
Range resolution operator
- What do two colons mean in PHP?
- What does the PHP token name T_PAAMAYIM_NEKUDOTAYIM mean?
- What is the difference between :: (double colon) and -> (arrow) in PHP?
- What exactly is late static binding in PHP?
- static::staticFunctionName()
- Unexpected T_PAAMAYIM_NEKUDOTAYIM, requires T_NS_Separator
Namespaces
- Backslash in PHP - what does it mean?
What does
- (backslash) do in PHP (5.3)?
->
Classes and Objects
- What is the name of the "->" PHP operator?
- Where do we use the object operator "->" in PHP?
- What is the difference between :: (double colon) and -> (arrow) in PHP?
- PHP syntax $var1->$var2 What does it mean?
- What does "->" mean in PHP?
=>
Array
- What does "=>" mean in PHP?
- Using in PHP =>
- foreach($ex as $k=>$v) What does $k => $v mean?
^
Bit operators
- How does the bitwise operator XOR ('^') work?
What does
- ^ mean in PHP?
>>
Bit operators
What does
- >> mean in PHP?
<<
Bit operators
- Strange printing behavior in PHP?
<<<
Heredoc or Nowdoc
- <<
- PHP expression <<
- In PHP, what does "<<<" stand for?
- Using <<in PHP
- What is this syntax in PHP?
=
Assignment operator
==
Comparison operators
- PHP What is the difference between equality (== double equality) and identity (=== triple equality) comparison operators?
- PHP != and == operators
- 3 different equals
- Type juggling and (strict) greater than/less than comparisons in PHP
===
Comparison operators
- What does "===" mean?
- PHP What is the difference between equality (== double equality) and identity (=== triple equality) comparison operators?
- 3 different equals
- Type juggling and (strict) greater than/less than comparisons in PHP
!==
Comparison operator
- What does the !== comparison operator in PHP mean?
- Is there a difference between !== and != in PHP?
!=
Comparison operator
- PHP != and == operators
- Is there a difference between !== and != in PHP?
- Compare, !== and !=
- <> What is the difference between != and
<>
Comparison operator
- PHP Operators <>
- https://stackoverflow.com/questions/589391
- <> What is the difference between != and
- Type juggling and (strict) greater than/less than comparisons in PHP
<=>
Comparison operators (since PHP 7.0)
- Spaceship (three-way comparison) operator
|
Bit operators
What is the difference between
- |? and || operator?
- Is there anything that using a single pipe "|" does in a function argument?
||
Logical operators
What is the difference between
- |? and || operator?
- PHP - and/or keywords
- || What exactly is it? meaning is?
- The behavior of the or operator in PHP
~
Bit operators
- What does the ~ operator here mean?
Arithmetic operators, array operators
- Use " " (array union operator) to merge two arrays, how does it work?
=
and-=
assignment operators
- = What is it used for?
- What does "$page -= 1" in my PHP documentation mean?
and--
Increment/Decrease Operators
- Understand the increment
- Answer the following
.=
Assignment operator
- What is the difference between .= and = in PHP?
- What is the .= (dot equals) operator in PHP?
.
String operators
- What is the difference between periods and commas when connecting echo and return?
- What is . (dot) used for PHP?
,
Function parameters
- What is the difference between periods and commas when connecting echo and return?
,
Variable declaration
- What does the comma in the variable declaration mean?
$$
Variable variable
What does
- $$ (dollar or double dollar) mean in PHP?
- What is "$$" in PHP
- $function() and $$variable
`
Execution operator
- What is the backtick `` called?
=
Short open tag
- What does this symbol mean in PHP =
- What does "=" mean in PHP?
- = What does it mean?
[]
Array (short syntax since PHP 5.4)
- PHP Array...What is the meaning of empty brackets?
What is the meaning of
- []
- Php array_push() and myArray[]
- What does [] mean when reading from a PHP array?
- Abbreviation of array: text
$var = []
Empty array
Opening and closing tags
- Can PHP short tags be used?
..
Double-dot character range
- Native PHP functions that allow double dot scope syntax
...
Parameter unpacking (since PHP 5.6)
**
Exponentiation (since PHP 5.6)
# One-line shell comment
- Can I use hashes for comments in PHP?
#[]
Properties (since PHP 8)
Bitwise operators
What is a point? Bits represent 1 or 0. Basically OFF(0) and ON(1)
What are bytes? A byte consists of 8 bits, and the highest value a byte can have is 255, which means every bit is set. We'll look at why the maximum value of a byte is 255.
This means 1 byte
1 2 4 8 16 32 64 128 = 255 (1 byte)
Some examples for better understanding
"AND" operator:
&
This will output the number 8. Why? Okay, let's look at an example using our table.
So you can see from the table that the only bit they share is 8 bits.
Second example
The two shared bits are 32 and 4, and 36 is returned after addition.
"OR" operator:
|
This will output the number 11. Why?
You will notice that we have 3 bits set in columns 8, 2 and 1. Add these together: 8 2 1 = 11.
Increment/Decrease Operator
Increment operator
--
Decrement operatorThey can be placed before or after variables.
If placed before the variable,firstincrease or decrease the variable, and then return the result. If placed after a variable,firstreturns the variable, and then performs increment/decrement operation.
For example: