我试图从分类标本和分类名称中获取相关数组。我有这个
foreach (get_terms('taxonomy') as $tax_term) {
$taxonomy_slug = $tax_term->slug;
$taxonomy_name = $tax_term->name;
}
问题是,这些只是粘在一起的字符串,我不知道如何将它们分开:\当我print_r
出来时,我得到:
term1term2term3term4
...
我需要的是一种分离它们的方法,然后创建如下所示的数组:
Array(
['term_1'] => Term 1
['term_2'] => Term 2
...
)
这可能吗?
答案 0 :(得分:0)
根据您在评论中的输入,我试图找出解决方案。希望这会对你有所帮助。
$terms = array();
foreach (get_terms('taxonomy') as $tax_term) {
$taxonomy_slug = $tax_term->slug;
$taxonomy_name = $tax_term->name;
$exploded = explode($taxonomy_name,$taxonomy_slug);
foreach ($exploded as $termValue) {
if (!empty($termValue)) {
$terms[$taxonomy_name."_".$termValue] = ucfirst($taxonomy_name)." ".$termValue;
}
}
}
echo "<pre>"; print_r($terms);