【发布时间】:2012-09-21 13:14:25
【问题描述】:
可能重复:
Implode array with “, ” and add “and ” before last item
在 Wordpress 中,我使用 PHP implode 用逗号分隔一系列字符串,这些字符串存储在一个数组中,如下所示:
Wordpress 循环遍历这个:
<?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; ?>
基本上,一系列字符串存储到 $credits 数组中,然后我使用 implode 将每个字符串用逗号分隔。
我需要在最后一个单词之前添加一个 & 符号而不是逗号。这里可以吗?
【问题讨论】: