Merging website info into an array 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-&gt;query("//div[@class='news-archive']//a/@href");
$titleQuery = $xpath-&gt;query("//div[@class='news-archive']//a");

$data = [];

foreach ($linkQuery as $link) {
    $data[] = array('link' =&gt; $link-&gt;value);
}

$i = 0;
foreach ($titleQuery as $title) {
    $data[$i]['title'] = $title-&gt;nodeValue;
    $i++;
}


I do like the structure of the Array:

Array (
    [0] =&gt; Array
        (
            [link] =&gt; http://www.gpupdate.net/nl/f1-nieuws/321783/force-india-vreest-voor-deelname-aan-laatste-test/
            [title] =&gt; Force India vreest voor deelname aan laatste test
        )
I think that one of the collections you iterate already has all the data you need. Try this:

$linkQuery = $xpath-&gt;query("//div[@class='news-archive']//a");
foreach ($linkQuery as $link) {
    $data[] = array('link' =&gt; $link-&gt;getAttribute('href'), 'title' =&gt; $link-&gt;nodeValue);
}


Btw. array_map() is another way for traversing two (or more) arrays simultaneously:

$group_elements = function($link, $title) {
    return array('link' =&gt; $link-&gt;value, 'title' =&gt; $title-&gt;nodeValue);
};
$data = array_map($group_elements, $linkQuery, $titleQuery);