PHP string concatenation [duplicate]
Solution 1:
Just use .
for concatenating.
And you missed out the $personCount
increment!
while ($personCount < 10) {
$result .= $personCount . ' people';
$personCount++;
}
echo $result;
Solution 2:
One step (IMHO) better
$result .= $personCount . ' people';
Solution 3:
while ($personCount < 10) {
$result .= ($personCount++)." people ";
}
echo $result;
Solution 4:
This should be faster.
while ($personCount < 10) {
$result .= "{$personCount} people ";
$personCount++;
}
echo $result;