【发布时间】:2016-05-14 23:15:52
【问题描述】:
我正在使用 Google Calendar API,试图从响应对象中获取 ID。
这是对象。
Google_Service_Calendar_CalendarList Object
(
[collection_key:protected] => items
[internal_gapi_mappings:protected] => Array
(
)
[etag] => "1454629096373000"
[itemsType:protected] => Google_Service_Calendar_CalendarListEntry
[itemsDataType:protected] => array
[kind] => calendar#calendarList
[nextPageToken] =>
[nextSyncToken] => CIj2xtSj38oCEj1nY2FsL....
[modelData:protected] => Array
(
[items] => Array
(
[0] => Array
(
[kind] => calendar#calendarListEntry
[etag] => "145461934381000"
[id] => tbcv49j3eg@group.calendar.google.com
[summary] => Appointments
[timeZone] => America/Chicago
[colorId] => 24
[backgroundColor] => #a47ae2
[foregroundColor] => #000000
[selected] => 1
[accessRole] => reader
[defaultReminders] => Array
(
)
)
[1] => Array
(
[kind] => calendar#calendarListEntry
[etag] => "14546290978873000"
[id] => o6lkfgdovcv2r8@group.calendar.google.com
[summary] => Test Calendar
[timeZone] => America/Chicago
[colorId] => 14
[backgroundColor] => #9fe1e7
[foregroundColor] => #000000
[selected] => 1
[accessRole] => reader
[defaultReminders] => Array
(
)
)
)
)
所以我这样做是为了将它们放入一个数组中。
foreach ($calendarList['items'] as $key => $value) {
$ids[] = $calendarList['items'][$key]['id'];
}
但我想以更面向对象的风格引用它们,例如
$calendarList->items->
我可以这样做吗?
【问题讨论】:
-
@ern 感谢您的文章。