Jump to content

help with foreach loop results


Recommended Posts

If i got it right ... you wana do something like this?


foreach ($array[key] as $key => $value){
$string .= $value.", ";
$string = substr($string, 0, -2); // Delete the last 2 characters
echo $string;


I would require more of your code in order to show you exacly how it's done but the above is an exemple.

Link to comment
Share on other sites

foreach($options['exc_cat'] as $cat) {
echo $cat;


this code returns 1 5


I want it to display as 1,5


I have been searching and tried substr($cat, 0, -1) but this strips all the commas from the string. the way I am returning the value, it prints as 1,5, I need the last comma after the 5 to go away. But the substr strips all commas which just donned on me that the foreach loop loops through, returns 1, then loops again and returns 5, I want to combine the total overall results into one string so that I can strip the trailing comma.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.