Click to See Complete Forum and Search --> : Add on to a varible


Pixel-Artist
08-18-2006, 09:47 PM
how do you add on stuff to the end of a varible?

blazes816
08-18-2006, 09:57 PM
the dot, '.'.

<?php
$a = "hello,";
$b = "world!"
$c = $a.$b;
echo $c;
?>

Outputs "hello, world!".

Pixel-Artist
08-18-2006, 09:59 PM
can you do it without setting the $a varible because its the output of a while.

I want each time it goes through the while it will addon to the end of the variable.

blazes816
08-18-2006, 10:48 PM
then in the while use

$a = $a.$b;

NogDog
08-19-2006, 09:54 AM
then in the while use

$a = $a.$b;
You can even shorten that to:

$a .= $b;
// note the "." before the "="

pcthug
08-20-2006, 04:30 AM
The most efficient method of adjoining stuff to the end of a variable is by using the concatenate equals operator. As NogDog's and the following example outline.

$b = "Hello ";
$b .= "There!"; // sets $b to "Hello There!", just like $b = $b . "There!";

LiLcRaZyFuZzY
08-20-2006, 04:55 AM
(That's what nogdog just said)