0

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.

2
  • 6
    Looks like xml, not json Commented Jan 9, 2014 at 13:05
  • json_decode() Commented Jan 9, 2014 at 13:05

1 Answer 1

1

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: https://www.php.net/ref.simplexml

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.