I'm scraping a title and a link from a website and placing them in a single array.
The $i
variable seems a bit wrong to me, or is it perfectly fine?
$linkQuery = $xpath->query("//div[@class='news-archive']//a/@href");
$titleQuery = $xpath->query("//div[@class='news-archive']//a");
$data = [];
foreach ($linkQuery as $link) {
$data[] = array('link' => $link->value);
}
$i = 0;
foreach ($titleQuery as $title) {
$data[$i]['title'] = $title->nodeValue;
$i++;
}
I do like the structure of the Array
:
Array (
[0] => Array
(
[link] => http://www.gpupdate.net/nl/f1-nieuws/321783/force-india-vreest-voor-deelname-aan-laatste-test/
[title] => Force India vreest voor deelname aan laatste test
)