我有这个代码应该显示一个数组列表,后面跟一个逗号和空格!但是我不希望最后一个在它之后有逗号和空格.
所以例如我想要tag1, tag2, tag3而不是tag1, tag2, tag3,
这是我的代码:
<?php $terms = get_the_terms( $the_post->ID, 'posts_tags' );
foreach ( $terms as $term ) {
echo $term->name;echo ", ";
} ?>
Run Code Online (Sandbox Code Playgroud)
Roc*_*mat 21
$output = array();
foreach($terms as $term){
$output[] = $term->name;
}
echo implode(', ', $output);
Run Code Online (Sandbox Code Playgroud)