PHP: Assignment Operators - Manual [PDF]

In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic, array uni

1 downloads 39 Views 176KB Size

Recommend Stories


Operators Manual
Raise your words, not voice. It is rain that grows flowers, not thunder. Rumi

Operators Manual
This being human is a guest house. Every morning is a new arrival. A joy, a depression, a meanness,

Operators Manual
If you want to become full, let yourself be empty. Lao Tzu

Operators Manual
The wound is the place where the Light enters you. Rumi

Operators Manual
What we think, what we become. Buddha

Operators Manual
Be grateful for whoever comes, because each has been sent as a guide from beyond. Rumi

493100 8250 Operators Manual 1985-89.pdf
Courage doesn't always roar. Sometimes courage is the quiet voice at the end of the day saying, "I will

biosite operators manual
In the end only three things matter: how much you loved, how gently you lived, and how gracefully you

DP-6900 Operators Manual
Just as there is no loss of basic energy in the universe, so no thought or action is without its effects,

M5 Ultrasound Operators Manual
And you? When will you begin that long journey into yourself? Rumi

Idea Transcript


Downloads Documentation Get Involved Help Search PHP 5.6.33 Released Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Errors Exceptions Generators References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security 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:

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:

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 objects, which are assigned by reference in PHP 5. 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

As of PHP 5, the new operator returns a reference automatically, so assigning the result of new by reference results in an E_DEPRECATED message in PHP 5.3 and later, and an E_STRICT message in earlier versions. For example, this code will result in a warning:

More information on references and their potential uses can be found in the References Explained section of the manual. add a note

User Contributed Notes 9 notes up down 279 straz at mac dot nospam dot com ¶ 13 years ago This page really ought to have table of assignment operators, namely, See the Arithmetic Operators page (http://www.php.net/manual/en/language.operators.arithmetic.php) Assignment Same as: $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 See the String Operators page(http://www.php.net/manual/en/language.operators.string.php) $a .= $b $a = $a . $b Concatenate See the Bitwise Operators page (http://www.php.net/manual/en/language.operators.bitwise.php) $a &= $b $a = $a & $b Bitwise And $a |= $b $a = $a | $b Bitwise Or $a ^= $b $a = $a ^ $b Bitwise Xor $a > $b Right shift

up down 50 Peter, Moscow ¶ 6 years ago Using $text .= "additional text"; instead of $text = $text ."additional text"; can seriously enhance performance due to memory allocation efficiency. I reduced execution time from 5 sec to .5 sec (10 times) by simply switching to the first pattern for a loop with 900 iterations over a string $text that reaches 800K by the end.

up down 21 Robert Schneider ¶ 2 years ago Be aware of assignments with conditionals. The assignment operator is stronger as 'and', 'or' and 'xor'.

up down 16 Hayley Watson ¶ 10 years ago bradlis7 at bradlis7 dot com's description is a bit confusing. Here it is rephrased. outputs abfoo bfoo Because the assignment operators are right-associative and evaluate to the result of the assignment is equivalent to and therefore

up down -9 ma dot bx dot ar at gamil dot com ¶ 3 years ago

up down -6 asc at putc dot de ¶ 2 years ago

up down -7 Hayley Watson ¶ 9 years ago

up down -18 bradlis7 at bradlis7 dot com ¶ 12 years ago

up down -24 haubertj at alfredstate dot edu ¶ 6 years ago

add a note Operators Operator Precedence Arithmetic Operators Assignment Operators Bitwise Operators Comparison Operators Error Control Operators Execution Operators Incrementing/Decrementing Operators Logical Operators String Operators Array Operators Type Operators Copyright © 2001-2018 The PHP Group My PHP.net Contact Other PHP.net sites Mirror sites Privacy policy

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.