Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 541285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:19:40+00:00 2026-05-13T10:19:40+00:00

From what I can tell, a SimpleXMLElement is just an array of other SimpleXMLElements,

  • 0

From what I can tell, a SimpleXMLElement is just an array of other SimpleXMLElements, plus some regular array values if there wasn’t a tag nested in another tag.

I have a SimpleXMLElement in a variable $data, and var_dump($data) gives me this:

object(SimpleXMLElement)#1 (33) {
  ["buyer-accepts-marketing"]=>
  string(4) "true"
...
...

but calling var_dump($data->buyer-accepts-marketing) gives me an error, and var_dump($data["buyer-accepts-marketing"]) gives me NULL. Calling var_dump($data->shipping-address->children()) gives me an error.

going like this:

foreach($data as $item) {
    var_dump($item);
}

gives a whole bunch of SimpleXMLElement objects, but oddly enough, no strings or ints.

What am I missing here? I want to take specific portions of it and pass them to a function, so for example, I don’t have to go

$data->billing-address->postal-code;

...

$data->shipping-address->postal-code;

...

and can just go

address($data->billing-address);
address($data->shipping-address);

etc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:19:40+00:00Added an answer on May 13, 2026 at 10:19 am

    SimpleXMLElement is not just an array. To access child elements, you must use object notation ($a->b) and to access attributes you must use array notation ($a['b']).

    Problem is, with object notation, valid tag names can be illegal PHP code.

    You need to do this:

    $data->{'buyer-accepts-marketing'};
    

    Note that this returns a SimpleXMLElement! The reason for this is that it can contain either just text, more child elements, or both. The output of var_dump() is very misleading for SimpleXMLElements. If you want to the text content of a single <buyer-accepts-marketing> tag, you have to do this:

    (string)$data->{'buyer-accepts-marketing'};
    

    Of course it is also perfectly legal to do this:

    (int)$data->{'buyer-accepts-marketing'};
    

    The reason this appears to work in some cases (such as echoing a SimpleXMLElement) is that the type conversions are implicit and automatic. You can’t echo an object, so PHP automatically converts it to a string.

    I have a love/hate relationship with SimpleXML. It makes things very easy only after you understand how complex the actual API is.

    Read up on the so-called “basic” examples to get a good handle on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From what I can tell Date and DateTime have the same functionality. Is there
In .NET, is there any way that I can tell from the HttpContext or
From what I can tell there is not way of telling if the drop
so from what i can tell, you have to specify artifacts and working directory
NSDecimalNumber is a subclass of NSNumber, and from what I can tell, it implements
i have invoked blackberry calender from my application can anyone tell me how to
From the question you can probably tell that I don't know much about code!
Can anybody tell how to retrieve data from database like that of Facebook's notification
Can anyone tell me how I can download a picture from a URL and
can anyone tell how to access MS SQL Server from objective c programatically

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.