>我正在尝试从分类蛞蝇和分类名称中获取关联的数组。我有这个
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
...
)
这可能吗?
根据您在评论中的输入,我试图找出解决方案。希望这对你有帮助。
$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);