Possible Duplicate:
Implode array with “, ” and add “and ” before last item
In Wordpress, I am using PHP implode to separate a series of strings with commas, that are stored in an array like so:
Wordpress Loop Iterates through this:
<?php unset($credits); ?>
<?php if(get_field('song_credits')):
while(has_sub_field('song_credits')):
$credits[] = get_sub_field('artist_name');
endwhile; ?>
<p><?php echo implode(', ', $credits); ?>.</p>
<?php endif; ?>
Basically, a series of strings is stored into the $credits array, and then I use implode to separate each string with a comma.
I need to add an ampersand right before the last word instead of a comma. Is this possible here?