ADS - Directory "Premium" Links

Klinsystem soluzioni per il trattamento dei pavimenti
Klinsystem produce levigatrici, aspirapolveri industriali e professionali, monospazzole, utensili diamantati, polveri e prodotti chimici lucidanti made in Italy per il trattamento di qualsiasi tipologia di pavimento quali marmo, granito, cemento, legno, terrazzo etc.
Studio di Psicologia e Psicoterapia Avezzano e L'Aquila
Allo studio di Psicologia e Psicoterapia di Avezzano possono rivolgersi le persone in tutto l'arco evolutivo di età: adulti singoli e in coppia, bambini, anziani, famiglie, organizzazioni sociali, che hanno necessità di un ascolto attento a cogliere e ad identificare i più precoci segnali di un dolore psicologico.
Ghiglo annunci
Annunci gratuiti inserimento senza bisogno di registrazione di immobili, veicoli, elettronica, animali, lavoro abbigliamento, hobby, per la casa e annunci di smarrimento. Semplice e veloce.
Assistenza caldaie vaillant Roma
Offre un servizio di assistenza manutenzione e riparazioni caldaie vaillant a roma e provincia.

Inserisci il tuo sito nella directory...

Manuale PHP

Assignment Operators

The basic assignment operator is "=". Your first inclination might be to think of this as "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:


= ($b 4) + 5// $a is equal to 9 now, and $b has been set to 4.


For arrays, assigning a value to a named key is performed using the "=>" operator. The precedence of this operator is the same as other assignment operators.

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:


$a += 5// sets $a to 8, as if we had said: $a = $a + 5;
$b "Hello ";
$b .= "There!"// sets $b to "Hello There!", just like $b = $b . "There!";


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

$b = &$a// $b is a reference to $a

print "$an"// prints 3
print "$bn"// prints 3

$a 4// change $a

print "$an"// prints 4
print "$bn"// prints 4 as well, since $b is a reference to $a, which has
              // been changed

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:

class {}

/* The following line generates the following error message:
 * Deprecated: Assigning the return value of new by reference is deprecated in...
$o = &new C;

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