I am using xpath to get various elements on a page. If I use a foreach loop like this foreach ($company as $node) { echo $node->nodeValue. "<br>"; } it works but I am only able to return values from one variable so that means I have to create two separate foreach loops. I want to be able to use the while loop so I can return both values from variable at the same time. The while loop doesnt return any error or values.
$doc = new DOMDocument();
@$doc->loadHTML($source);
$xpath = new DOMXpath($doc);
$company = $xpath->query("//*[@class='name']");
$address = $xpath->query("//*[@class='address']");
$i = 0;
while ($i < count($company)) {
echo $company->nodeValue. "<br>";
echo $address->nodeValue. "<br><br>";
$i++;
}
They are
NodeLists, to retrieve individual nodes by index, use->item()