雖然我映射數組中包含的頁面上的所有鏈接,但我想檢查每個鏈接是否插入到此數組中,如果沒有,插入它。向循環中的數組添加值
我試圖使用代碼低音沒有成功,因爲「foreach $ arr」沒有通過新的值。
include_once('simple_html_dom/simple_html_dom.php');
$arr = array('http://www.domain.com');
foreach ($arr as $key => &$item) {
$html = file_get_html($item);
// Find category links
foreach($html->find('a[href^=http://www.domain.com/dep/]') as $element) {
if (!in_array($element->href, $arr))
$arr[] = $element->href;
}
}
print_r($arr);
重要提示:我需要在原始數組中搜索並添加值,而不是複製(foreach)。
您的預期結果是什麼? – Rizier123
請刪除「&」來自foreach –
嗨!我編輯了更具體的問題。謝謝! –