I'm using PHPSimpleHTMLDOM Parser and I'd like to somehow implement a foreach loop with two conditions. I'm getting the headlines that I want, but I also want to get the href which applies to that particular headline. If I write a nested foreach loop for the href alone, it loops way too many times and outputs many duplicates. Here's my code:
include_once ('simple_html_dom.php');
$html = file_get_html('somehtml.com');
foreach ($html->find('ul[class=headlines] li') as $return){
//if I put another foreach here, too many duplicates
echo $return;
}
The other foreach loop looks like this:
foreach ($html->find('ul[class=headlines] li a') as $href){
$link = $href->href;
echo $link;
}
How can I put these two conditions into one foreach loop so the link corresponds to the correct article and I can pass it along to another php file to do something with it? Thanks in advance