While populating an array with data from a SimpleXML call, PHP throws exception to what it believes as 'Undefined' keys, however, the output is actually correct.
$doc = new SimpleXmlElement($http_result, LIBXML_NOCDATA);
$result = array();
$x = 0;
foreach($doc->users->user as $item) {
$result['user'][$x]['id'] .= $item->id;
$result['user'][$x]['name'] .= $item->name;
$result['user'][$x]['email'] .= $item->email;
$x++;
}
print json_encode($result);
This actually outputs what I expect, i.e. {"user":[{"id":"4843977","name":"Test New User","email":"[email protected]"}]}
However, the following errors are also present, and I'm not totally sure why - this doesn't appear in 5.2.6 but does for 5.2.10
Notice: Undefined index: user in /var/vhosts/sys-dev/docs/file.php on line 36
Notice: Undefined offset: 0 in /var/vhosts/sys-dev/docs/file.php on line 36
Notice: Undefined index: id in /var/vhosts/sys-dev/docs/file.php on line 36
Notice: Undefined index: name in /var/vhosts/sys-dev/docs/file.php on line 37
Notice: Undefined index: email in /var/vhosts/sys-dev/docs/file.php on line 38
Notice: Undefined offset: 1 in /var/vhosts/sys-dev/docs/file.php on line 36
Notice: Undefined index: id in /var/vhosts/sys-dev/docs/file.php on line 36
Notice: Undefined index: name in /var/vhosts/sys-dev/docs/file.php on line 37
Notice: Undefined index: email in /var/vhosts/sys-dev/docs/file.php on line 38
Notice: Undefined offset: 2 in /var/vhosts/sys-dev/docs/file.php on line 36
Notice: Undefined index: id in /var/vhosts/sys-dev/docs/file.php on line 36
Notice: Undefined index: name in /var/vhosts/sys-dev/docs/file.php on line 37
Notice: Undefined index: email in /var/vhosts/sys-dev/docs/file.php on line 38