0

我有一个名为 $picasa_feed 的对象,如下所示:

SimpleXMLElement Object
(
    [guid] => https://picasaweb.google.com/data/entry/base/user/0000000000000000/albumid/0000000000000000?alt=rss&hl=en_US
    [pubDate] => Fri, 12 Dec 2008 20:00:00 +0000
    [category] => http://schemas.google.com/photos/2007#album
    [title] => My Pictures
    [description] => ...
    [link] => https://picasaweb.google.com/0000000000000000/MyAlbum
    [author] => Me
)

我想将属性值放入关联数组的元素中:

$data_to_save['title'] = $picasa_feed->title;

当我这样做时, $data_to_save 的值是

Array
(
    [title] => SimpleXMLElement Object
        (
            [0] => My Pictures
        )
}

我想要的是

Array
(
    [title] => My Pictures
}

我做错了什么,我该如何解决?

4

3 回答 3

1

将其转换为字符串:

$data_to_save['title'] = (string) $picasa_feed->title;
于 2013-02-13T21:00:45.197 回答
0

您想通过将 SimpleXMLElement__toString转换为字符串来调用它的魔法方法。尝试:$data_to_save['title'] = (string)$picasa_feed->title;

于 2013-02-13T21:00:43.030 回答
0

这应该有效:

$data_to_save['title'] = (string) $picasa_feed->title;
于 2013-02-13T21:02:58.393 回答