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
Just use . for concatenating.
And you missed out the $personCount increment!
while ($personCount < 10) {
$result .= $personCount . ' people';
$personCount++;
}
echo $result;
No comments:
Post a Comment