-1

I have connected an api and gotten a response in xml format which I have converted into array but now I am stuck at how to iterate through this array. For example I want to get all the comments from this array. Here is my array

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [type] => array
        )

    [survey] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [censored] => false
                    [comments] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [nil] => true
                                )

                        )

                    [completed-at] => 2017-12-29T08:47:08-05:00
                    [flagged-for-follow-up] => false
                    [has-notes] => false
                    [invited-at] => 2017-12-28T18:52:40-05:00
                    [net-promoter-label] => promoter
                    [public-response] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [nil] => true
                                )

                        )

                    [recommendation-likelihood] => 10
                    [updated-at] => 2017-12-29T08:47:08-05:00
                    [customer-reference] => 553
                    [customer-full-name] => Bill Hoeninger
                    [public-reviewer-name] => B.H.
                    [notes] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [type] => array
                                )

                        )

                )
            [1] => SimpleXMLElement Object
                (
                    [censored] => false
                    [comments] => Friendly, attention to scheduling,, effective coaching
                    [completed-at] => 2017-12-29T05:26:03-05:00
                    [flagged-for-follow-up] => false
                    [has-notes] => false
                    [invited-at] => 2017-12-28T18:56:18-05:00
                    [net-promoter-label] => promoter
                    [public-response] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [nil] => true
                                )

                        )

                    [recommendation-likelihood] => 10
                    [updated-at] => 2017-12-29T05:26:29-05:00
                    [job-reference] => 19855
                    [customer-full-name] => Javaid Yousuf
                    [public-reviewer-name] => J.Y.
                    [notes] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [type] => array
                                )

                        )

                )

            [2] => SimpleXMLElement Object
                (
                    [censored] => false
                    [comments] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [nil] => true
                                )

                        )

                    [completed-at] => 2017-12-29T00:39:06-05:00
                    [flagged-for-follow-up] => false
                    [has-notes] => false
                    [invited-at] => 2017-12-28T18:54:58-05:00
                    [net-promoter-label] => promoter
                    [public-response] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [nil] => true
                                )

                        )

                    [recommendation-likelihood] => 10
                    [updated-at] => 2017-12-29T00:39:06-05:00
                    [job-reference] => 21505
                    [customer-full-name] => Julia Taylor
                    [public-reviewer-name] => J.T.
                    [notes] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [type] => array
                                )

                        )

                )

        )

)

Help me out please I am stuck at this

Thank you

0

Looks like you would need to loop the XML object results, eg:

$comments = array();
foreach ($object->survey as $index => $survey) {
    if (is_string($survey->comments)) {$comments[$index] = $survey->comments;}
}
print_r($comments); // to see comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.