What is this?
This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
Why is this?
Stack Overflow does not allow searching for particular characters. As a consequence, many questions about operators and other syntax tokens are not found easily when searching for them. This also makes closing duplicates more difficult. The list below is to help with this issue.
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from the PHP Manual.
What should I do here?
If you have been pointed here by someone because you have asked such a question, please find the particular syntax below. The linked pages to the PHP manual along with the linked questions will likely answer your question then. If so, you are encouraged to upvote the answer. This list is not meant as a substitute to the help others provided.
The List
If your particular token is not listed below, you might find it in the List of Parser Tokens .
&
Bitwise Operators or References
-
What does it mean to start a PHP function with an ampersand?
-
Understanding PHP's & operator
-
PHP "&" operator
-
difference between & and && in PHP
-
What does "&" mean here in PHP?
-
what does & mean in this case?
-
What does the & sign mean in PHP?
-
What does this signature mean(&) in PHP?
-
How does "&" operator work in PHP function?
-
What does & in &2 mean in PHP?
=&
References
-
Reference assignment operator in php =&
-
what do "=&" / "&=" operators in php mean?
-
What do the '&=' and '=&' operators do? [PHP]
-
What does =& mean in PHP?
-
'AND' vs '&&' as operator
-
difference between & and && in PHP
-
PHP: Is there a difference between operators AND and && here?
-
PHP - and / or keywords
-
What does the percent sign mean in PHP?
-
What is the PHP operator % and how to use it in real world examples?
-
What is the use of @ symbol in php?
-
PHP - 'At' symbol before variable name: @$_POST
-
PHP functions and @functions
-
Should I use @ in my PHP code?
-
What is ?: in PHP 5.3?
-
What is the PHP ? : operator called and what does it do?
-
?: operator PHP
-
Where can I read about conditionals done with ? and :
-
Using PHP 5.3 ?: operator
:
Alternative syntax for control structures , Ternary Operator
::
Scope Resolution Operator , Namespaces
-
What do two colons mean in PHP?
-
What's the meaning of the PHP Token Name T_PAAMAYIM_NEKUDOTAYIM
-
In PHP, whats the difference between :: (double colon) and -> (arrow)?
-
When to use class::function or class->function, is there a preferred method?
-
What exactly is late-static binding in PHP?
-
static::staticFunctionName()
-
Unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting T_NS_Separator
-
What is the "->" PHP operator called and how do you say it when reading code out loud?
-
where we use object operator "->" in php
-
In PHP, whats the difference between :: (double colon) and -> (arrow)?
-
What does this PHP syntax mean: $var1->$var2
-
Absolutely basic PHP question about the "-> " syntax
=>
Arrays
-
What does "=>" mean in PHP?
-
What does '=>' sign in php means?
-
Use of => in PHP
-
What does $k => $v in foreach($ex as $k=>$v) mean?
-
What does <<<END mean in PHP?
-
PHP <<<EOB
-
In PHP, what does "<<<" represent?
-
Using <<<CON in PHP
-
What's this kind of syntax in PHP?
-
php == vs === operator
-
How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?
-
PHP != and == operators
-
The 3 different equals
-
What does "===" mean?
-
php == vs === operator
-
How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?
-
The 3 different equals
-
PHP != and == operators
-
Is there a difference between !== and != in PHP?
-
comparing, !== versus !=
-
What is the difference between <> and !=
-
What is the difference between the | and || operators?
-
PHP - and / or keywords
-
What exactly does || mean?
+
Arithmetic Operators , Array Operators
++
Incrementing/Decrementing Operators
-
What is the difference between .= and += in php
-
To understand a line of PHP
-
What does .= mean in PHP?
<?=
Short Open Tags
[]
Arrays
-
PHP : What does mean of []
-
Php array_push() vs myArray[]
-
What does [] mean when reading from a php array?
Source: Tips4all
Incrementing / Decrementing Operators
ReplyDelete++ increment operator
-- decrement operator
Example Name Effect
---------------------------------------------------------------------
++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one.
--$a Pre-decrement Decrements $a by one, then returns $a.
$a-- Post-decrement Returns $a, then decrements $a by one.
These can go before or after the variable. Putting this operator before the variable is slightly faster.
If put before the variable, the increment / decrement operation is done to the variable first then the result is returned. If put after the variable, the variable is first returned, then the increment / decrement operation is done.
For example:
$apples = 10;
for ($i = 0; $i < 10; ++$i)
{
echo 'I have ' . $apples-- . " apples. I just ate one.\n";
}
Live example
In the case above ++$i is used, since it is faster. $i++ would have the same results.
However, you must use $apples--, since first you want to display the current number of apples, and then you want to subtract one from it.
You can also increment letters in PHP:
$i = "a";
while ($i < "c")
{
echo $i++;
}
Once z is reached aa is next, and so on.
Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.
Stack Overflow Posts:
Understanding Incrementing