0

I have an array $array1

    Array
   (
        [0] => SimpleXMLElement Object
        (
            [galleryid] => gallery.xml
            [galleryname] => Default
            [createdat] => 9/8/2010 5:55 pm
            [description] => Default
        )
   }

when i am running

foreach($array1 as $node)
{
 print_r($node) ; 
}

am getting

SimpleXMLElement Object
(
    [galleryid] => gallery.xml
    [galleryname] => Default
    [createdat] => 9/8/2010 5:55 pm
    [description] => Default
)

How i can display galleryid and gallery name

0

2 Answers 2

4

Just like you would access any other SimpleXMLElement Object:

foreach($array1 as $node)
{
    echo $node->galleryname;
    echo $node->galleryid;
}
Sign up to request clarification or add additional context in comments.

2 Comments

... i.e. the array is a one-dimensional array containing objects (which have properties), not a multidimensional array.
@BlaM judging by the OPs previous question, I'd say the array is a result of an XPath query, so it is singledim.
2

Both galleryid & galleryname are object properties, you can access object properties with the following syntax.

foreach($array1 as $node){
     echo $node->galleryid;
     echo $node->galleryname;
}

Plenty of resources online to learn object oriented PHP and the correct syntax for accessing properties and methods.

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.