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

  • Home
  • SEARCH
  • 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 8754695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:41:10+00:00 2026-06-13T13:41:10+00:00

I am having trouble on my php simple xml object. I have the following

  • 0

I am having trouble on my php simple xml object.

I have the following xml data in my log

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [title] => test
            [scanner] => Data
            [id] => WordData
            [position] => 1800
            [error] => false
            [num] => 6
        )

    [subpod] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [title] => Surnames
                        )

                    [plaintext] => Common (US population: 650 people, white: 63% | black: 35%)
                    [img] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (

                                    [alt] => Common (US population: 650 people, white: 63% | black: 35%)
                                    [title] => Common (US population: 650 people, white: 63% | black: 35%)
                                    [width] => 349
                                    [height] => 18
                                )

                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [title] => Cities
                        )

                    [plaintext] => Littleton Common (Massachusetts, 2789 people)
                    [img] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (

                                    [alt] => Littleton Common (Massachusetts, 2789 people)
                                    [title] => Littleton Common (Massachusetts, 2789 people)
                                    [width] => 287
                                    [height] => 18
                                )

                        )

                )

            [2] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [title] => Buildings
                        )

                    [plaintext] => Rotunda on Woolwich Common (London, Greater London)
                    [img] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (

                                    [alt] => Rotunda on Woolwich Common (London, Greater London)
                                    [title] => Rotunda on Woolwich Common (London, Greater London)
                                    [width] => 356
                                    [height] => 18
                                )

                        )

                )
              .....more simpleXmlElement object
          )
)

my php varible $xmlObj = SimpleXMLElement Object but when I have the following

if (is_array($xmlObj->subpod)){
    echo 'is array';    
}else {
    echo 'not array';
}

the output is always ‘not array’ and I want my codes to echo ‘is array’

I thought $xmlObj->subpod is an array.
When I test $xmlObj->subpod[0]->plaintext, it will actually return strings.
I am not sure how to solve this problem. Can anyone help?

  • 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-06-13T13:41:11+00:00Added an answer on June 13, 2026 at 1:41 pm

    If you were to var_dump($xmlObj->subpod), you would see that it is still a SimpleXMLElement object. However, it can still be called as if it were an array. (See the note after this example, which hints that the class implements ArrayAccess, even though the class documentation doesn’t.)

    The correct way to check for this structure would be using SimpleXMLElement::count():

    if ($xmlObj->subpod->count() > 0) { ... }
    

    Edit: The output in your question is presumably from print_r, which is sometimes rather unhelpful in its output (e.g. telling you something is an array when it’s not). Try using var_dump instead, as it’s generally more useful for debugging. The only caveat here is that you don’t get to see the entire nested object structure for SimpleXMLElement objects!

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

Sidebar

Related Questions

I am having trouble with writing a simple(!) PHP function to return an array
I'm having trouble with PHP text parsing I have a txt file which has
I'm having trouble to make a simple CRUD in my site. I have a
I'm having some trouble saving some data after using PHP's simplexml_load_file function. I want
Im having some trouble looping through some xml data. The xml file is structured
I'm having some trouble with an xml file, I have found all sorts of
I'm having trouble with multidimensional arrays in PHP. I'm assuming this should be simple
I'm having trouble with simple xml to assign it as variable. Here is my
I'm having trouble getting PHP's SimpleXML to work with our XML feed . I'm
I'm having trouble connecting to my ftp server in PHP. I'm able to log

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.