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 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(). 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); 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 Link to comment https://forums.phpfreaks.com/topic/141479-solved-foreach-with-commas/#findComment-740574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.