array_unique() 在 php 简单 html dom

array_unique() in php simple html dom

我编写了代码 blow 以从 url:

中获取所有 unique links
include_once ('simple_html_dom.php');

$html = file_get_html('http://www.example.com');

foreach($html->find('a') as $element){ 
  $input = array($element->href = $element->href . '<br />');
  print_r(array_unique($input));}

但我真的不明白为什么它也显示重复的link! 函数array_uniquesimple html dom有什么问题吗? 我猜还有另一件事与这个问题有关:当你执行它时,你会看到它提取的所有 link 都在一个键中我的意思是:

array(key  => all values)

有没有人可以解决这个问题?

我相信你更想要这样:

$temp = array();
foreach($html->find('a') as $element) { 
    $temp[] = $element->href;
}

echo '<pre>' . print_r(array_unique($temp), true) . '</pre>';