So I'm trying to iterate through an XML feed and paginate it but I've run into a problem. When I try to get the index (key) of the current array it outputs a string "campDetails" on every iteration instead of an incrementing integer like 0,1,2,3
Here is a sample of the XML format
<campaigns> <campDetails> <campaign_id>2001</campaign_id> <campaign_name>Video Chat Software</campaign_name> <url>http://www.fakeurl.com</url> </campDetails>
<?php
$call_url = "https://www.fakeurl.com";
if($xml = simplexml_load_file($call_url, "SimpleXMLElement", LIBXML_NOCDATA)):
foreach($xml as $i => $offers):
$offer_link = $offers->url;
$offer_raw_name = $offers->campaign_name;
echo $i . " " . $offer_link; ?> </br> <?php echo $offer_raw_name;
endforeach;
endif;
?>
Output to be expected:
0 http://www.fakeurl.com
Video Chat Software
Actual output:
campDetails http://www.fakeurl.com
Video Chat Software
EDIT: Thank you for your answers everyone. It seems I was given incorrect information from another question on here. I was told that $i would keep a numerical index for the current iteration.
print_r($xml); (obviously more results but this is the first)
SimpleXMLElement Object ( [campDetails] => Array ( [0] => SimpleXMLElement Object ( [campaign_id] => 2001 [campaign_name] => Video Chat Software [url] => http://www.fakeurl.com/ )