开发者

Array parsing in PHP

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


Just like you would access any other SimpleXMLElement Object:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜