0

私は現在、以下のような配列を持っていますが、ショーの結果を一意の配列 (説明) に表示したいだけです。しかし、私は同じ結果を得続けますか?

これが私の配列です:

$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 に答える