试图从对象中获取值

时间:2014-01-29 20:57:27

标签: php arrays object

我有以下对象输出,我正在尝试抓住field_data而我无法做到。我最终希望获得field_data的value1和value2,这似乎不可能。

我尝试过的事情包括:

$schedule->field_data

$schedule['field_data]

我如何以正确的方式获取数据?

Array ( [0] => stdClass Object ( [vid] => 74 [uid] => 1 [title] => Schedule Dates 1 [log] => [status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [nid] => 55 [type] => schedule_dates [language] => und [created] => 1391028058 [changed] => 1391028058 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1391028058 [revision_uid] => 1 [body] => Array ( ) [field_date] => Array ( [und] => Array ( [0] => Array ( [value] => 2014-01-09 00:00:00 [value2] => 2014-01-24 00:00:00 [rrule] => [timezone] => UTC [timezone_db] => UTC [date_type] => datetime ) ) ) [field_sold_out] => Array ( [und] => Array ( [0] => Array ( [value] => 0 ) ) ) [rdf_mapping] => Array ( [rdftype] => Array ( [0] => sioc:Item [1] => foaf:Document ) [title] => Array ( [predicates] => Array ( [0] => dc:title ) ) [created] => Array ( [predicates] => Array ( [0] => dc:date [1] => dc:created ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [changed] => Array ( [predicates] => Array ( [0] => dc:modified ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) [body] => Array ( [predicates] => Array ( [0] => content:encoded ) ) [uid] => Array ( [predicates] => Array ( [0] => sioc:has_creator ) [type] => rel ) [name] => Array ( [predicates] => Array ( [0] => foaf:name ) ) [comment_count] => Array ( [predicates] => Array ( [0] => sioc:num_replies ) [datatype] => xsd:integer ) [last_activity] => Array ( [predicates] => Array ( [0] => sioc:last_activity_date ) [datatype] => xsd:dateTime [callback] => date_iso8601 ) ) [cid] => 0 [last_comment_timestamp] => 1391028058 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => backend [picture] => 0 [data] => b:0; [weight_weight] => [print_html_display] => 0 [print_html_display_comment] => 0 [print_html_display_urllist] => 0 [print_pdf_display] => 0 [print_pdf_display_comment] => 0 [print_pdf_display_urllist] => 0 [print_pdf_size] => [print_pdf_orientation] => ) )

1 个答案:

答案 0 :(得分:3)

很难从未格式化的代码中判断出来,但是应该这样做:

$schedule[0]->field_date

您无法跳过[0],因为$schedule是一个数组。