As the title says, or of course it could be comma before each item except the first.
I have a custom field that returns an array. That part works fine with
<?php
$values = get('recording_details_genre');
foreach($values as $value){
printf('%s',$value);
}
?>
I have tried various ways to control adding a comma and space between each item so that I do not end up with a trailing comma. I am no PHP wiz. After a couple of dozen combinations I cam up with this, is there a better way?
<?php
$values = get('recording_details_genre');
$count = count($values);
$i = $count;
foreach($values as $value){
$i = $i -1;
if ($i < ($count - 1)) {
printf(', %s',$value); }
else{
printf('%s',$value);
}
}
?>