【发布时间】:2017-05-31 09:33:58
【问题描述】:
这是我获取类别 ID 和名称的代码:
<?php
$categories = get_categories('orderby=name&hide_empty=0');
foreach ($categories as $category):
$catids = $category->term_id;
$catname = $category->name;
endforeach;
?>
现在,我想在数组中列出 id 和名称:
array(
$catids => $catname,
);
我希望数组是这样的:
array(
'1' => 'Ctegory 1',
'2' => 'Ctegory 2',
'3' => 'Ctegory 3',
);
其中 1,2,3 是类别 ID,类别 1、类别 2、类别 3 是类别名称
任何帮助将不胜感激。
谢谢。
【问题讨论】: