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 mysql table what i have and i dont want to be showed in next results, so i want to build a string like this
1,23,54,67 (comma separated)
So that string will be in mysql query to exclude results that already have been shown. how can i do that?
Should be with implode? How can i achieve that?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With