0

Below is my code and I want to extract information of[field] => Array of index [1].It means [1] => 1030.670044. This is xml file,and I want to store in my database,but unable to loop this in php. Please Help me.

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [version] => 1.0
        )

    [meta] => SimpleXMLElement Object
        (
            [type] => resource-list
        )

    [resources] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [start] => 0
                    [count] => 168
                )

            [resource] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [classname] => Quote
                                )

                            [field] => Array
                                (
                                    [0] => USD/KRW
                                    [1] => 1030.670044
                                    [2] => KRW=X
                                    [3] => 1398752590
                                    [4] => currency
                                    [5] => 2014-04-29T06:23:10+0000
                                    [6] => 0
                                )

                        )

                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [classname] => Quote
                                )

                            [field] => Array
                                (
                                    [0] => SILVER 1 OZ 999 NY
                                    [1] => 0.051059
                                    [2] => XAG=X
                                    [3] => 1398721323
                                    [4] => currency
                                    [5] => 2014-04-28T21:42:03+0000
                                    [6] => 400
                                )

                        )

1 Answer 1

2

This is a SimpleXML object. If the variable is called $xml you can access the field[1] like this:

foreach ($xml->resources->resource as $res) {
   var_dump( $res->field[1] );
}
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.