I\'m using a foreach loop to echo out some values from my database, I need to strip the last comma from the last loop if that makes sense.
My loop is just simple, as
$arraySize = count($results); for($i=0; $i<$arraySize; $i++) { $comma = ($i<$arraySize) ? ", " : ""; echo $results[$i]->name.$comma; }
Better:
$resultstr = array(); foreach ($results as $result) { $resultstr[] = $result->name; } echo implode(",",$resultstr);