Here is my Xml code:
SimpleXMLElement Object
(
[resultsRows] => SimpleXMLElement Object
(
[row] => Array
(
[0] => SimpleXMLElement Object
(
[dimension] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => date
[value] => 20140102
[label] => Date
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => browserType
[value] => Chrome
[label] => Browser Type
)
)
)
[metric] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => visitDuration
[value] => 1242
[label] => Avg. Visit Duration
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => bounces
[value] => 3
[label] => Bounces
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => repeatVisitors
[value] => 0
[label] => Repeat Visitors
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => newVisitors
[value] => 5
[label] => New Visitors
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => visits
[value] => 10
[label] => Visits
)
)
[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[name] => pageViews
[value] => 66
[label] => Page Views
)
)
)
)
)
)
)
Above Xml array need to print like key and values type.The array showing like dimension and metric.I want print the values inside @attributes nested array like key and value.
Thanks.
Found in the comments on php SimpleXml documentation:
function xml2array ( $xmlObject, $out = array () )
{
foreach ( (array) $xmlObject as $index => $node )
$out[$index] = ( is_object ( $node ) ) ? xml2array ( $node ) : $node;
return $out;
}
Check the docs here: http://cl1.php.net/ref.simplexml