I have an array like this:
[participants] => Array
(
[0] => 9
[1] => 8
[2] => 12
)
I want to put it in another variable to look like this:
"9,8,12"
I tried with the code below but it does not output anything:
$mem = "";
for($i = 0; $i < count($participants); $i++)
{
$mem.$participants[$i];
}
echo $mem;
What can be the problem?
$mem.$participants[$i];, but why bother when you can useimplode().$memyou have to do the=sign first. So$mem .= $participants[$i];. To put comas in between you can do$mem .= ($i > 0) ? ','.$participants[$i] : $participants[$i];but you can use theimplode()function to do this for you as the others indicated.