How to remove last comma from the output of a foreach()
loop?
Can someone please help modify this code for me.
$sth = $dbh->query('SELECT * FROM `stage5` ORDER BY `stage5`.`lenght` DESC');
$sth->setFetchMode(PDO::FETCH_ASSOC);
$result = $sth->fetchAll();
foreach($result as $r) {
echo $r['lenght'], ",";
}
This prints
105.4,102.1,
Below would be correct
105.4,102.1
I have read many posts related to this but, I can't get it working and I don't get it. Any help is appreciated!