timmah1 Posted January 19, 2009 Share Posted January 19, 2009 How can I separate a foreach statement with commas? I'm trying to show temperatures from the database for each user, right now, there are 2 in there It shows the temps, but together 99.697.3 I need it to show like 99.6, 97.3 If I just echo the value with a comma, it puts one on the end as well <?php $temps[$charts['temp']] = $charts['username']; } foreach ($temps as $f) //$temp = implode(' ', $f); echo $f.","; ?> How is this accomplished? I tried split(), but either I didn't do it right, or it just don't work Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/141479-solved-foreach-with-commas/ Share on other sites More sharing options...
DarkWater Posted January 19, 2009 Share Posted January 19, 2009 Check out implode(). Quote Link to comment https://forums.phpfreaks.com/topic/141479-solved-foreach-with-commas/#findComment-740561 Share on other sites More sharing options...
Mark Baker Posted January 19, 2009 Share Posted January 19, 2009 Looking at the OP's code, he tried implode without really understanding it. Don't bother with foreach at all. Just do echo implode(', ', $temps); Quote Link to comment https://forums.phpfreaks.com/topic/141479-solved-foreach-with-commas/#findComment-740564 Share on other sites More sharing options...
timmah1 Posted January 19, 2009 Author Share Posted January 19, 2009 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/141479-solved-foreach-with-commas/#findComment-740574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.