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 . '",'; } ?>