0
我有兩個foreach循環,我希望匹配第一個和第二個的輸出。第一個從起始頁面抓取標題,第二個foreach導航到子頁面進行描述。我似乎不能輸出這兩個內聯,使標題顯示與相關的描述。將一個foreach的元素合併爲另一個
//1st foreach:
$title = array();
foreach ($html->find('.event-box .event-details h1') as $t){
$title[] = $t->plaintext;
}
echo implode('<br>',$title);'<br>';
//this lists all $title found on page ahead of the below foreach (obvisouly)
//2nd foreach:
// loop through each link
foreach ($anchors as $anchor) {
// Create the new link to follow and parse
$urlTemp = $baseUrl . $anchor->href;
$html2 = new simple_html_dom();
$html2->load_file($urlTemp);
//Descriptions
foreach($html2->find('div[id=content-area]') as $article) {
} $para = array();
foreach($article->find('p') as $p) {
$para[] = $p->innertext; }
echo 'DESC: '.implode('<br>',$para);'<br>';
echo "<hr/>";
$html2->clear();
unset($htm2);
}
我想獲得的輸出順序所以$title
遵循符合$para
每個迭代。 $title
需要與$para
$title //From first foreach - 1st in $title[]
$para //From second foreach - 1st in $para[]
</hr>
$title //From first foreach - 2nd in $title[]
$para //From second foreach - 2nd in $para[]
</hr>
$title
$para
匹配....等