Page 1 of 1

the .= operator

Posted: Wed Apr 07, 2004 9:14 pm
by sutejok
Hi,

can anyone tell me what does the ".=" operator do? or probably how does it work..?

$themelist .= "$file ";



thx[/quote]

Posted: Wed Apr 07, 2004 9:21 pm
by John Cartwright
.= means add it to a varible

Code: Select all

<?

$variable .= 'hello ';
$variable .= 'Johnny';

echo $varable;

//outputs Hello Johnny

?>

Posted: Wed Apr 07, 2004 9:22 pm
by tim
.= is a string operator.

an example using your vars:
$themelist = "hello ";
$themelist .= "tim.";

// this would output: hello tim.

Posted: Wed Apr 07, 2004 9:45 pm
by Illusionist
the . is a concatenation operator:

Code: Select all

$num = 1;
$text = "Number: " . $num;
echo $text;
//will output: Number: 1
the = is an asignment operator:

Code: Select all

$text = "Number 1";
echo $text;
//will output Number 1
when combining them together it is like saying
$text = $text . $num ::

Code: Select all

$text = "Number ";
$num = 1;
$text .= $num; //same as $text = $text . $num
//will output Number 1
there are also others like
+=
-=
/=
*=
++
--

Posted: Wed Apr 07, 2004 9:46 pm
by tim
Illusionist wrote: when combining them together it is like saying
is saying its a string operator, lol.

Posted: Wed Apr 07, 2004 10:09 pm
by Illusionist
yes it is a string operator, but more specifically the concatenating assignment operator. But using that operator is the same as saying $text = $text . $num

Posted: Wed Apr 07, 2004 10:12 pm
by Illusionist
i left out a few on my other assignment operators above, here is a more coimplete list from here:

Code: Select all

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    $a = $a << $b    Left shift
$a >>= $b    $a = $a >> $b      Right shift