user1721449 user1721449 - 5 months ago 8
jQuery Question

Parsing XML file after converting to json with PHP

I have an XML url that I need to parse and paginate on a jquery ajax request. I'm not too much experience in PHP and I'm trying to figure out how I can get the values of each item?

My code:

$xmlFile = simplexml_load_file($xmlURL);
$json = json_encode($xmlFile);
$array = json_decode($json,TRUE);



echo "<pre>";
print_r($array);
echo "</pre>";


The output (trying to traverse through this):

Array
(
[item] => Array
(
[0] => Array
(
[title] => English Matters Book Group for English Language Learners
[date] => Wednesday, June 15, 2016
[time] => 10:00 AM

Answer

A standard foreach loop would suffice:

<?php
foreach ($array['item'] as $item) {
    echo $item['title'] . '<br />';
}