添加值以在array_merge下拉列表中充当中断

时间:2012-10-25 20:57:16

标签: php sql wordpress array-merge

我有三个数组获得不同的帖子类型,然后合并为Wordpress管理员中的下拉列表。我正在尝试插入空值/中断以使下拉更容易阅读。

这是数组和array_merge:

// creating an array of pages

$featpages = array();
$pages = get_pages();
$pages[""] = "";
foreach ($pages as $page) {
$featpages[ $page->post_title ] = $page->ID;    
}

// creating an array of posts

$postargs = array('numberposts' => 0);
$featposts = array();
$posts = get_posts($postargs);
$posts[""] = "";
foreach ($posts as $post) {
$featposts[ $post->post_title ] = $post->ID;
}

// creating an array of activities

$actargs = array('post_type' => 'activity', 'numberposts' => 0);
$featacts = array();
$acts = get_posts($actargs);
$acts[""] = "";
foreach ($acts as $act) {
$featacts[ $act->post_title ] = $act->ID;
}

// creating a combined array of pages and tours

$links = array_merge((array)$featpages, (array)$featacts, (array)$featposts);

我希望每个[""] = "";会在每个集合之间添加一个空行,但它只适用于一个 - 我猜是因为它们看起来与array_merge相同?

1 个答案:

答案 0 :(得分:0)

[""] = "";将覆盖下一个

使用[] = '';代替