Hello Guys i need to do this,
I have a common loop
foreach ($stuffs as $stuff) {
echo $stuff;
}
Lets assume $stuff is an \'id\' of a my
Should be as simple as:
$string = implode(",",$stuffs);
echo $string
This worked in my case (detects if isn't the loop last iteration):
foreach($array as $key => $val){
...
if($key!==count($array)-1){echo ',';}
}
If you really wanna have the loop:
$values = "";
foreach ($stuffs as $stuff) {
$values != "" && $values .= ",";
$values .= $stuff;
}
echo $values;
I suggest using implode, but the loop can really give you more power if you wanna do some further stuff.
implode should be the tool:
implode(",", $stuffs);
will return a comma separated list.
$myarray=array(1,2,"hello",4,5);
echo implode(",", $myarray);
returns
1,2,hello,4,5