PHP string concatenation

Illep picture Illep · Jul 11, 2012 · Viewed 148.2k times · Source

I need to know if its possible to concatenate strings, as follows ? and if not, what is the alternative of doing so ?

while ($personCount < 10) {
$result+= $personCount . "person ";
}

echo $result;

it should appear like 1 person 2 person 3 person etc..

You cann't use the + sign in concatenation so what is the alternative ?

Answer

abhshkdz picture abhshkdz · Jul 11, 2012

Just use . for concatenating. And you missed out the $personCount increment!

while ($personCount < 10) {
    $result .= $personCount . ' people';
    $personCount++;
}

echo $result;