Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一段代码用于提取我的 WordPress 类别。就像这样:
<?php foreach ($terms as $term) { echo $term->slug ;} ?>
该代码将生成如下类别列表:
BrazilItalyThailand
但我需要输出是这样的:
"Brazil","Italy","Thailand"
我怎样才能做到这一点?
<?php foreach($terms as $term) { $cats[] = $term->slug; } $str = '"'.implode('","', array_unique($cats)).'"'; ?>
不需要正则表达式!
<?php foreach ($terms as $term) { echo '"' . $term->slug . '",'; } ?>