spfoonnewb Posted March 24, 2007 Share Posted March 24, 2007 I have this function to list values from a form POST... What it does right now is if there is only one posted it does not add the comma. If there are more than one posted it adds the comma after each one.. What I want it to do is not add the comma on the LAST one. <?php foreach ($_POST["eval"] as $eval) { $arr[] = array($eval); } foreach ($_POST["eval"] as $eval) { $count = count($arr); if ($count > 1) { echo "$eval, "; } else { echo "$eval"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/44082-solved-foreach-list-help-needed/ Share on other sites More sharing options...
MadTechie Posted March 24, 2007 Share Posted March 24, 2007 what i do is add the comma then remove it IE <?php $tmp = ""; foreach ($_POST["eval"] as $eval) { $tmp .= $eval.", "; } $tmp = trim($tmp,", "); echo $tmp; ?> hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/44082-solved-foreach-list-help-needed/#findComment-214032 Share on other sites More sharing options...
spfoonnewb Posted March 24, 2007 Author Share Posted March 24, 2007 I eventually got it to work with.. since it cant repeat numbers.. $get_end = end($arr); if ($event == $get_end[0]) { echo "$eval"; } elseif ($count > 1) { echo "$eval, "; } else { echo "$eval"; } Quote Link to comment https://forums.phpfreaks.com/topic/44082-solved-foreach-list-help-needed/#findComment-214038 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.