As I’m a bit of php noob, I’m not sure whether to go with preg_replace() or to explode() then implode(). Either way, I don’t know how to go about it.
I’m in wordpress, and I’m running this code:
<?php $terms = wp_get_post_terms($post->ID,'jobtype');
foreach($terms as $term){echo ', ' . $term->name;} ?>
I need to capture into a string the echo ', ' . $term->name; and remove that first ', '.
Even if there’s a different way I can echo the term names, could you guys (and gals) help me out?
Thanks!
Old school:
As PHP 5.3 introduced anonymous functions [docs],
array_map[docs] becomes more interesting for these “one time” jobs:Or maybe more descriptive with a reusable function:
But as said, this only works if you use PHP 5.3.