我有一段代码用于提取我的WordPress类别。就像这样:
<?php foreach ($terms as $term) { echo $term->slug ;} ?>
该代码将生成如下类别的列表:
BrazilItalyThailand
但我需要输出如下:
"Brazil","Italy","Thailand"
我该怎么做?
答案 0 :(得分:2)
<?php
foreach($terms as $term)
{
$cats[] = $term->slug;
}
$str = '"'.implode('","', array_unique($cats)).'"';
?>
不需要正则表达式!
答案 1 :(得分:1)
<?php
foreach ($terms as $term) {
echo '"' . $term->slug . '",';
}
?>