0

我目前有一个看起来像下面的数组,但我只想在数组中显示显示结果,其中是唯一的(描述),我假设使用 array_unique?但我一直得到相同的结果?

这是我的数组:

$taglist = array(5) { 
[0]=> array(5) { 
    ["id"]=> string(2) "27" 
    ["page_id"]=> string(2) "18" 
    ["description"]=> string(10) "Web Design" 
    ["slug"]=> string(10) "web-design" 
    ["visibility"]=> string(7) "visible"
} 
[1]=> array(5) { 
    ["id"]=> string(2) "29" 
    ["page_id"]=> string(2) "18" 
    ["description"]=> string(3) "Tutorials" 
    ["slug"]=> string(3) "tutorials" 
    ["visibility"]=> string(7) "visible"
}
[2]=> array(5) {
    ["id"]=> string(2) "31"
    ["page_id"]=> string(2) "21"
    ["description"]=> string(3) "tag" 
    ["slug"]=> string(3) "tag"
    ["visibility"]=> string(7) "visible"
}
[3]=> array(5) { 
    ["id"]=> string(2) "32" 
    ["page_id"]=> string(2) "21" 
    ["description"]=> string(10) "Web Design" 
    ["slug"]=> string(10) "web-design" 
    ["visibility"]=> string(7) "visible"
}
}

这是我的时间:

$items      = array();
$results    = $taglist;

foreach ($results as $result)
{
$items[]= $result['description'];
$items  = array_unique($items);
}

echo '<ul>';
while ($tag_item = current($items))
{
echo '<li><a href="/'.$page['slug'].'/tag/'.$tag_item['slug'].'/">'.$tag_item['description'].'</a></li>';
    next($items);
}
echo '</ul>';
4

1 回答 1

0
$taglist = array(
0 => array('description'=>'one'),
1 => array('description'=>'two'),
2 => array('description'=>'one'),
3 => array('description'=>'three'),
4 => array('description'=>'one'),
);

// echo var_export($taglist, 1);  // uncomment to see the diff vs var_dump()

foreach($taglist as $tag){
$new[] = $tag['description'];

}

var_dump(array_unique($new));
于 2012-11-11T19:35:43.070 回答