0

When I print_r($var) I get the result below.

SimpleXMLElement Object
(
    [SEND_FILE] => SimpleXMLElement Object
        (
            [FILEID] => 123
            [GUID] => 456
            [SUMMARY] => SimpleXMLElement Object
                (
                    [NB_PAYMENTS] => 1
                )
        )
)

How can I get the value of the FILEID element in a variable? If I do

print $result->SEND_FILE->FILEID[0]

then I just get the number - what I want, no mention of a SimpleXML Object. But if I put this variable in an array, as such

$res['file_id'] = $result->SEND_FILE->FILEID[0]

and then print_r($res) I get:

Array
    (
        [file_id] => SimpleXMLElement Object
            (
                [0] => 307466
            )
    )

How can I get it to remove the [0] / SimpleXMLElement Object?

2
  • SimpleXml is not an array. It only behaves remotely like one. Commented Dec 1, 2011 at 12:08
  • Understood but ... I'm trying to send this array to a web service but the file_id key has to be just a numeric value, not an SimpleXML Object. Commented Dec 1, 2011 at 12:12

2 Answers 2

2

This will look not too elegant, but try casting the result to integer (if the type is known):

$res['file_id'] = (int)$result->SEND_FILE->FILEID[0]
Sign up to request clarification or add additional context in comments.

1 Comment

Confirmed, casting necessary in this case.
1

Why do you append the [0] at the end? You dont need that. You should simply do

print $result->SEND_FILE->FILEID;

And that should be enough.

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.