我有这样一段代码,应该显示一个数组中的值列表,每个值后面跟着逗号和空格!但是,我不想在最后一个值后面加上逗号和空格。
例如,我想要 tag1, tag2, tag3
而不是 tag1, tag2, tag3,
这是我的代码:
<?php $terms = get_the_terms( $the_post->ID, 'posts_tags' );
foreach ( $terms as $term ) {
echo $term->name;echo ", ";
} ?>
implode
。例如,请查看 @rocket 的回答。 - Nanne