What Does "=≫" Mean in PHP

Reference — What does this symbol mean in PHP?

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.

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.

Pre-increment is a little bit faster because it really increments the variable and after that 'returns' the result. Post-increment creates a special variable, copies there the value of the first variable and only after the first variable is used, replaces its value with second's.

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

What does @ mean in PHP?

The @ operator tells PHP to suppress error messages, so that they will not be shown.

For instance, using:

$result = mysql_query("this is an invalid query");

would result in a warning being shown, telling you that the MySQL query is invalid, while

$result = @mysql_query("this is still an invalid query");

would not.

Note, however, that this is very bad programming practice as it does not make error disappear, it just hides them, and it makes debugging a heck of a lot worse since you can't see what's actually wrong with your code.

Instead of using @, you should disable error_reporting and display_errors just display_errors in php.ini

What does => mean in PHP?

=> is the separator for associative arrays. In the context of that foreach loop, it assigns the key of the array to $user and the value to $pass.

Example:

$user_list = array(
'dave' => 'apassword',
'steve' => 'secr3t'
);

foreach ($user_list as $user => $pass) {
echo "{$user}'s pass is: {$pass}\n";
}
// Prints:
// "dave's pass is: apassword"
// "steve's pass is: secr3t"

Note that this can be used for numerically indexed arrays too.

Example:

$foo = array('car', 'truck', 'van', 'bike', 'rickshaw');
foreach ($foo as $i => $type) {
echo "{$i}: {$type}\n";
}
// prints:
// 0: car
// 1: truck
// 2: van
// 3: bike
// 4: rickshaw

What does operator -> mean in PHP?

In your example, $controller is a PHP object created somewhere, and permissionCheck is a function defined in that object that is being called with the variable $ret being passed to it. Check this: Reference - What does this symbol mean in PHP?.

What is the meaning of |= in php?

This is bitwise OR operator

$var1 |= $var2; is equal to $var1 = $var1 | $var2;

What does :: mean in php?

It's the 'Scope Resolution Operator'.

The Scope Resolution Operator (also called Paamayim Nekudotayim) or in
simpler terms, the double colon, is a token that allows access to
static, constant, and overridden properties or methods of a class.

http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php

What does '<?=' mean in PHP?

It's a shorthand for <?php echo $a; ?>.

It's enabled by default since 5.4.0 regardless of php.ini settings.

What does double question mark (??) operator mean in PHP

It's the "null coalescing operator", added in php 7.0. The definition of how it works is:

It returns its first operand if it exists and is not NULL; otherwise it returns its second operand.

So it's actually just isset() in a handy operator.

Those two are equivalent1:

$foo = $bar ?? 'something';
$foo = isset($bar) ? $bar : 'something';

Documentation: http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.coalesce

In the list of new PHP7 features: http://php.net/manual/en/migration70.new-features.php#migration70.new-features.null-coalesce-op

And original RFC https://wiki.php.net/rfc/isset_ternary


EDIT: As this answer gets a lot of views, little clarification:

1There is a difference: In case of ??, the first expression is evaluated only once, as opposed to ? :, where the expression is first evaluated in the condition section, then the second time in the "answer" section.

What does =& mean in PHP?

It passes by reference. Meaning that it won't create a copy of the value passed.

See:
http://php.net/manual/en/language.references.php (See Adam's Answer)

Usually, if you pass something like this:

$a = 5;
$b = $a;
$b = 3;

echo $a; // 5
echo $b; // 3

The original variable ($a) won't be modified if you change the second variable ($b) . If you pass by reference:

$a = 5;
$b =& $a;
$b = 3;

echo $a; // 3
echo $b; // 3

The original is changed as well.

Which is useless when passing around objects, because they will be passed by reference by default.



Related Topics



Leave a reply



Submit