Home » Questions » Reference - What does this symbol mean in PHP?

Reference - What does this symbol mean in PHP?

Answered
1
1

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


=& References


&= Bitwise Operators


&& Logical Operators


% Arithmetic Operators


!! Logical Operators


@ Error Control Operators


?: Ternary Operator


: Alternative syntax for control structures, Ternary Operator


:: Scope Resolution Operator


\ Namespaces


-> Classes And Objects


=> Arrays


^ Bitwise Operators


>> Bitwise Operators


<< Bitwise Operators


<<< Heredoc or Nowdoc


= Assignment Operators


== Comparison Operators


=== Comparison Operators


!== Comparison Operators


!= Comparison Operators


<> Comparison Operators


| Bitwise Operators


|| Logical Operators


~ Bitwise Operators


+ Arithmetic Operators, Array Operators


+= Assignment Operators


++ Incrementing/Decrementing Operators


.= Assignment Operators


. String Operators


, Function Arguments


$$ Variable Variables


` Execution Operator


<?= Short Open Tags


[] Arrays


NOTE: This question was originally posted at StackOverflow.com by anon

  • Sharon
    I know this isn't strictly PHP, but what about including a link to phpdoc.org for phpDocumentor comment syntax, which is commonly used and it's also impossible to search for /**?

    NOTE: This comment was originally posted at StackOverflow.com by Mike

  • Jon
    • Jon
    • 12 years ago
    • 5
    I ran into this problem a lot too (not being able to search for special characters), which is why I made SymbolHound, a search engine that doesn't ignore special characters. I also posted it on StackApps.

    NOTE: This comment was originally posted at StackOverflow.com by dncrane

  • Keith
    Well, from the heading Why is this?, I'd guess it's because "The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them".

    NOTE: This comment was originally posted at StackOverflow.com by Herbert

  • Steve
    Related: meta.stackoverflow.com/a/149852/168606 - it saddens me to see people still casting closevotes on this despite it's proven value and utility to the PHP tag.

    NOTE: This comment was originally posted at StackOverflow.com by Gordon

  • Arthur
    This is more comprehensive. Thanks for adding this.

    NOTE: This comment was originally posted at StackOverflow.com by sandun dhammika

Good Answer
78
0

Incrementing / Decrementing Operators

++ 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:

NOTE: This answer was originally posted at StackOverflow.com by Peter Ajtai

  • You must to post comments
0
0
    syntax    name                  discription 
    x == y    Equality          True if x and y have the same key/value pairs
    x != y    Inequality            True if x is not equal to y
    x === y   Identity          True if x and y have the same key/value pairs in the same   order and of the same types
    x !== y   Non-identity          True if x is not identical to y
    ++ 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
    x and y   And                   True if both x and y are true x=6 y=3 (x < 10 and y > 1) returns true
    x && y    And                   True if both x and y are true x=6 y=3 (x < 10 && y > 1) returns true
    a . b     Concatenation     Concatenate two strings     "Hi" . "Ha"

NOTE: This answer was originally posted at StackOverflow.com by Ankur Saxena

  • You must to post comments
1
0

Bitwise Operator

What is a bit? A bit is a representation of 1 or 0. Basically OFF(0) and ON(1)

What is a byte? A byte is made up of 8 bits and the highest value of a byte is 255, which would mean every bit is set. We will look at why a byte’s maximum value is 255.

-------------------------------------------
|      1 Byte ( 8 bits )                  |
-------------------------------------------
|Place Value | 128| 64| 32| 16| 8| 4| 2| 1|     
-------------------------------------------

This representation of 1 Byte

1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 = 255 (1 Byte)

A few examples for better understanding

The “AND” operator: &

$a =  9;
$b = 10;
echo $a & $b;

This would output the number 8. Why? Well let’s see using our table example.

-------------------------------------------
|      1 Byte ( 8 bits )                  |
-------------------------------------------
|Place Value | 128| 64| 32| 16| 8| 4| 2| 1|     
-------------------------------------------
|      $a    |   0|  0|  0|  0| 1| 0| 0| 1|    
-------------------------------------------
|      $b    |   0|  0|  0|  0| 1| 0| 1| 0|
------------------------------------------- 

So you can see from the table the only bit they share together is the 8 bit.

Second example

$a =  36;
$b = 103;
echo $a & $b; // This would output the number 36.
$a = 00100100
$b = 01100111

The two shared bits are 32 and 4, which when added together return 36.

The “Or” operator: |

$a =  9;
$b = 10;
echo $a | $b;

This would output the number 11. Why?

$a = 00001001
$b = 00001010

You will notice that we have 3 bits set, in the 8, 2, and 1 columns. Add those up: 8+2+1=11.

NOTE: This answer was originally posted at StackOverflow.com by Ankur Saxena

  • You must to post comments
Showing 3 results
Your Answer
Guest Author
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website
CAPTCHA*
Enter the characters shown on the image.