I am trying to access data inside a php object. I am confused about what the exact stynax is. Here is the output of the object:
stdClass Object ( [vid] => 10 [uid] => 1 [title] => Beachhead Don [log] =>
[status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [ds_switch] => [nid] =>
10 [type] => product [language] => und [created] => 1357668665 [changed] => 1358198386
[tnid] => 0 [translate] => 0 [revision_timestamp] => 1358198386 [revision_uid] => 1
[model] => B 3000 [list_price] => 0.00000 [cost] => 0.00000 [sell_price] => 1.00000
[weight] => 0 [weight_units] => lb [length] => 0 [width] => 0 [height] => 0
[length_units] => in [pkg_qty] => 1 [default_qty] => 1 [unique_hash] =>
2eec0fcc8483f3a3541870fb24223296 [ordering] => 0 [shippable] => 0 [price] => 1.00000
[body] => Array ( [und] => Array ( [0] => Array ( [value] => Description info
))))))))))))))))))))))))))))))))))))))0 [summary] => [format] => filtered_html
[safe_value] =>Description info ))))))))))))))))))))))))))))))))))))))0[safe_summary]
=> ) ) ) [uc_product_image] => Array ( [und] => Array ( [0] => Array ( [fid] => 11
[alt] => [title] => [width] => 90 [height] => 120 [uid] => 1 [filename] =>
beachhead_don.jpg [uri] => public://beachhead_don.jpg [filemime] => image/jpeg
[filesize] => 14342 [status] => 1 [timestamp] => 1357668665 [rdf_mapping] => Array ( )
) ) ) [field_author] => Array ( [und] => Array ( [0] => Array ( [value] => John B.
Romesier [format] => [safe_value] => John B. Romesier ) ) ) [field_publisher] => Array
( [und] => Array ( [0] => Array ( [value] => Unknown [format] => [safe_value] =>
Unknown ) ) ) [field_release_date] => Array ( [und] => Array ( [0] => Array ( [value]
=> Mar 2012 [format] => [safe_value] => Mar 2012 ) ) ) [field_number_of_pages] => Array
( [und] => Array ( [0] => Array ( [value] => 123 ) ) ) [field_catagory] => Array (
[und] => Array ( [0] => Array ( [tid] => 4 ) ) ) [field_book_type] => Array ( [und] => Array ( [0] => Array ( [tid] => 1 ) ) ) [field_isbn] => Array ( ) [field_about_the_author] => Array ( [und] => Array ( [0] => Array ( [value] => Beachhed Don authoer............................ [format] => [safe_value] => Beachhed Don authoer............................ ) ) ) [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] => 1357668665 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; [entity_view_prepared] => 1 )
I am trying to retrive the [value] of Description info ))))))))))))))))))))))))))))))))))))))0
I tried this
<?php
$node = menu_get_object(); //drupal code
if ( !empty($node) ) {
print $node ->body=>und=>0=>value;
}?>
and got an error about the '=' sign. What is the proper way to get my data?
[body] and [und] are arrays, so access them like this:
echo $node->body['und'][0]['value'];
It should be:
$node->body['und'][0]['value']
'Body' and 'und' are Arrays and need to be accessed with array syntax([]).
Accessing these values directly is sometimes frowned upon in drupal. You may want to look into: http://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_render/7
Related
Could you please help me? I need to know how to access the values of this response from an API call using PHP.
Array ( [queryIds] => Array ( [0] => lHLLapn7EH ) [timedOutRealtimeData] => [realtimeDataMissing] => [cacheFreshness] => FRESH [prunedResult] => [novaCost] => 0 [novaRequestDuration] => 19 [wasCached] => 1 [minSampleRate] => 1 [timeComputed] => 1558794556710 [novaRuntime] => 199 [hitChunkGroupByLimit] => [throttleTime] => 0 [data] => Array ( [series] => Array ( [0] => Array ( [0] => Array ( [setId] => [value] => 843 ) ) [1] => Array ( [0] => Array ( [setId] => [value] => 22 ) ) ) [seriesLabels] => Array ( [0] => Array ( [0] => 0 [1] => C5241; GB ) [1] => Array ( [0] => 0 [1] => C9999; GB ) ) [seriesMeta] => Array ( [0] => Array ( [eventGroupBys] => Array ( [0] => C5241 [1] => GB ) [segmentIndex] => 0 [eventIndex] => 0 [eventGroupBy] => C5241; GB ) [1] => Array ( [eventGroupBys] => Array ( [0] => C9999 [1] => GB ) [segmentIndex] => 0 [eventIndex] => 0 [eventGroupBy] => C9999; GB ) ) [seriesCollapsed] => Array ( [0] => Array ( [0] => Array ( [setId] => [value] => 843 ) ) [1] => Array ( [0] => Array ( [setId] => [value] => 22 ) ) ) [xValues] => Array ( [0] => 2019-05-25 ) ) [partialMergedAndNewUserInformation] => [transformationIds] => Array ( [0] => 2696 ) [backend] => novaV2 )
You can access them using
Array ( [0] => C9999 [1] => GB ) -> $arr['data']['seriesMeta'][0]['eventGroupBys']
Array ( [setId] => [value] => 20) -> $arr['data']['seriesMeta'][0][0]
I am using PHP Simple HTML DOM Parser to gather some text from another website. When I use file_get_html($url) then I get the error, "Message: file_get_contents(http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html): failed to open stream: HTTP request failed! HTTP/1.1 416 Requested Range Not Satisfiable"
So I can use str_get_html($url) and I get a return but I can't find any elements afterward. Here is my code:
$data['yb_data_reviews'] = '';
$yb_reviews[] = '';
$yb_url = 'http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html';
if($yb_url){
$yb_dom = str_get_html($yb_url);
foreach($yb_dom->find('div.detailItem') as $yb_review) {
$item['author'] = $yb_review;
$yb_reviews[] = $item;
}
$data['yb_data_reviews'] = $yb_reviews;
}
print_r($data['yb_data_reviews']);
My return is blank. If I just return $yb_dom then I get:
simple_html_dom Object ( [root] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [1] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object *RECURSION* ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [callback] => [lowercase] => 1 [original_size] => 71 [size] => 71 [pos:protected] => 71 [doc:protected] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html [char:protected] => [cursor:protected] => 2 [parent:protected] => simple_html_dom_node Object ( [nodetype] => 5 [tag] => root [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( [0] => simple_html_dom_node Object ( [nodetype] => 3 [tag] => text [attr] => Array ( ) [children] => Array ( ) [nodes] => Array ( ) [parent] => simple_html_dom_node Object *RECURSION* [_] => Array ( [4] => http://www.yellowbook.com/profile/great-wall-restaurant_1855353442.html ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) ) [parent] => [_] => Array ( [0] => -1 [1] => 2 ) [tag_start] => 0 [dom:simple_html_dom_node:private] => simple_html_dom Object *RECURSION* ) [noise:protected] => Array ( ) [token_blank:protected] => [token_equal:protected] => =/> [token_slash:protected] => /> [token_attr:protected] => > [_charset] => UTF-8 [_target_charset] => UTF-8 [default_br_text:protected] => [default_span_text] => [self_closing_tags:protected] => Array ( [img] => 1 [br] => 1 [input] => 1 [meta] => 1 [link] => 1 [hr] => 1 [base] => 1 [embed] => 1 [spacer] => 1 ) [block_tags:protected] => Array ( [root] => 1 [body] => 1 [form] => 1 [div] => 1 [span] => 1 [table] => 1 ) [optional_closing_tags:protected] => Array ( [tr] => Array ( [tr] => 1 [td] => 1 [th] => 1 ) [th] => Array ( [th] => 1 ) [td] => Array ( [td] => 1 ) [li] => Array ( [li] => 1 ) [dt] => Array ( [dt] => 1 [dd] => 1 ) [dd] => Array ( [dd] => 1 [dt] => 1 ) [dl] => Array ( [dd] => 1 [dt] => 1 ) [p] => Array ( [p] => 1 ) [nobr] => Array ( [nobr] => 1 ) [b] => Array ( [b] => 1 ) [option] => Array ( [option] => 1 ) ) )
What am I doing wrong that I can't return any elements using str_get_html()? Any help is appreciated. Thanks.
I have this array:
stdClass Object
(
[tid] => 26001835
[vid] => 5
[name] => AppleTV
[description] => My description
[format] => filtered_html
[weight] => 0
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608990
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => Apple-TV.png
[uri] => public://Apple-TV.png
[filemime] => image/png
[filesize] => 2103
[status] => 1
[timestamp] => 1405346182
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.something.com
[format] =>
[safe_value] => http://www.something.com
)
)
)
[field_learn_more] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://something.com/somepage
[format] =>
[safe_value] => http://something.com/somepage
)
)
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => network
)
)
)
)
stdClass Object
(
[tid] => 26001834
[vid] => 5
[name] => Playstation - USA
[description] => My description
[format] => filtered_html
[weight] => 2
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608991
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => ps4network.png
[uri] => public://ps4network.png
[filemime] => image/png
[filesize] => 4566
[status] => 1
[timestamp] => 1405346218
)
)
)
[field_buy_now_button_link] => Array
(
[und] => Array
(
[0] => Array
(
[value] => http://www.somesite.com
[format] =>
[safe_value] => http://somesite.com
)
)
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => blast_areas
)
)
)
)
stdClass Object
(
[tid] => 26001836
[vid] => 5
[name] => Brighthouse Networks
[description] => My description
[format] => filtered_html
[weight] => 3
[vocabulary_machine_name] => how_to_watch_device
[field_device_image] => Array
(
[und] => Array
(
[0] => Array
(
[fid] => 26608993
[alt] =>
[title] =>
[width] => 194
[height] => 102
[uid] => 26000697
[filename] => brighthouse.png
[uri] => public://brighthouse.png
[filemime] => image/png
[filesize] => 8392
[status] => 1
[timestamp] => 1405358781
)
)
)
[field_buy_now_button_link] => Array
(
)
[field_learn_more] => Array
(
)
[field_device_category] => Array
(
[und] => Array
(
[0] => Array
(
[value] => ppv_provider
)
)
)
)
I want to sort the array by the array by the value in field_device_category. Basically, I want to group the results but first I need to make sure all the objects are sorted by field_device_category.
Thanks in advance!
Use usort for this kind of sorting. It uses Quicksort in the background and takes a user-defined function to compare the array elements:
usort($array, "complicatedArrayComparer");
function complicatedArrayComparer($a,$b)
{
if ($a['field_device_category'] == $b['field_device_category']) {
return 0;
}
return ($a['field_device_category'] < $b['field_device_category']) ? -1 : 1;
}
How can I to have access to the "title" or "id" of my books in /me/books.reads (via graph api explorer I can see it, but not fetch it for my app).
I,ve trying
$books = $facebook->api('/me/book.reads','GET' );
foreach($books['data'] as $book) {
echo $book;
}
but doesn't work.
What I need to do?
UPDATE
Using print_r ($book);
Array ( [id] => 1404041189817636 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-11T05:23:56+0000 [publish_time] => 2013-08-11T05:23:56+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 103118839728079 [url] => https://www.facebook.com/pages/O-alienista/103118839728079 [type] => books.book [title] => O alienista ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402725673282521 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:06:56+0000 [end_time] => 2013-08-08T12:06:56+0000 [publish_time] => 2013-08-08T12:06:56+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724833282605 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:05:28+0000 [end_time] => 2013-08-08T12:05:28+0000 [publish_time] => 2013-08-08T12:05:28+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724089949346 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:02:20+0000 [end_time] => 2013-08-08T12:02:20+0000 [publish_time] => 2013-08-08T12:02:20+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724086616013 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:02:17+0000 [end_time] => 2013-08-08T12:02:17+0000 [publish_time] => 2013-08-08T12:02:17+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402724056616016 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-08T12:02:05+0000 [end_time] => 2013-08-08T12:02:05+0000 [publish_time] => 2013-08-08T12:02:05+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402246609997094 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-07T15:06:54+0000 [end_time] => 2013-08-07T15:06:54+0000 [publish_time] => 2013-08-07T15:06:54+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1402246209997134 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-07T15:05:16+0000 [end_time] => 2013-08-07T15:05:16+0000 [publish_time] => 2013-08-07T15:05:16+0000 [application] => Array ( [name] => cultdynamo-alfa [namespace] => cultdynamoalfa [id] => 486466824776147 ) [data] => Array ( [book] => Array ( [id] => 10151106849476668 [url] => http://samples.ogp.me/344468272304428 [type] => books.book [title] => Snow Crash ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1401338750087880 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T22:51:44+0000 [publish_time] => 2013-08-05T22:51:44+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 10150941236166867 [url] => http://www.goodreads.com/book/show/13583337-clube-da-luta [type] => good_reads:book [title] => Clube da Luta ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1400891206799301 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T02:57:48+0000 [publish_time] => 2013-08-05T02:57:48+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 10150604461117511 [url] => http://www.goodreads.com/book/show/6072069-cidade-de-deus [type] => good_reads:book [title] => Cidade De Deus ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1400890130132742 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T02:52:18+0000 [publish_time] => 2013-08-05T02:52:18+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 108088695879860 [url] => https://www.facebook.com/pages/On-the-Road/108088695879860 [type] => books.book [title] => On the Road ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1400889916799430 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-05T02:51:27+0000 [publish_time] => 2013-08-05T02:51:27+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 113172245363155 [url] => https://www.facebook.com/pages/Maus/113172245363155 [type] => books.book [title] => Maus ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) ) Array ( [id] => 1399682946920127 [from] => Array ( [name] => Inaldo Eleuterio [id] => 100006353053787 ) [start_time] => 2013-08-03T03:13:42+0000 [publish_time] => 2013-08-03T03:13:42+0000 [application] => Array ( [name] => Books [id] => 174275722710475 ) [data] => Array ( [book] => Array ( [id] => 108006402553308 [url] => https://www.facebook.com/pages/V-for-Vendetta/108006402553308 [type] => books.book [title] => V for Vendetta ) ) [type] => books.reads [no_feed_story] => [likes] => Array ( [count] => 0 [can_like] => 1 [user_likes] => ) [comments] => Array ( [count] => 0 [can_comment] => 1 [comment_order] => chronological ) )
You were basically improperly accessing the array. Based on the structure of the array, here's how you can access the title and id of the books:
$books = $facebook->api('/me/book.reads','GET' );
foreach ($books as $book)
{
echo "ID: ".$book['data']['book']['id'];
echo "Title: ".$book['data']['book']['title'];
}
Let me know if this works and makes sense to you :)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Able to see a variable in print_r()'s output, but not sure how to access it in code
I've got a complex array variable called $data. I need to pull out one very buried value: [url] in [field_website]. Here's the raw print_r() output of the $data variable:
stdClass Object ( [node_title] => CMI2 [nid] => 3 [field_data_field_website_node_entity_type] => node [field_data_field_blog_node_entity_type] => node [field_data_field_rss_node_entity_type] => node [field_data_field_twitter_node_entity_type] => node [field_data_field_yammer_node_entity_type] => node [field_data_field_facebook_node_entity_type] => node [field_data_field_flickr_node_entity_type] => node [field_data_field_youtube_node_entity_type] => node [_field_data] => Array ( [nid] => Array ( [entity_type] => node [entity] => stdClass Object ( [vid] => 3 [uid] => 1 [title] => CMI2 [log] => [status] => 1 [comment] => 1 [promote] => 0 [sticky] => 0 [nid] => 3 [type] => social_source [language] => und [created] => 1356040541 [changed] => 1356040541 [tnid] => 0 [translate] => 0 [revision_timestamp] => 1356040541 [revision_uid] => 1 [field_website] => Array ( [und] => Array ( [0] => Array ( [url] => http://cmi2.yale.edu [title] => [attributes] => Array ( ) ) ) ) [field_blog] => Array ( ) [field_rss] => Array ( ) [field_twitter] => Array ( [und] => Array ( [0] => Array ( [url] => http://twitter.com/yalecmi2 [title] => [attributes] => Array ( ) ) ) ) [field_facebook] => Array ( ) [field_youtube] => Array ( ) [field_flickr] => Array ( ) [field_yammer] => Array ( ) [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] => 1356040541 [last_comment_name] => [last_comment_uid] => 1 [comment_count] => 0 [name] => admin [picture] => 0 [data] => b:0; ) ) ) [field_field_website] => Array ( [0] => Array ( [rendered] => Array ( [#markup] => http://cmi2.yale.edu [#access] => 1 ) [raw] => Array ( [url] => http://cmi2.yale.edu [title] => http://cmi2.yale.edu [attributes] => Array ( ) [display_url] => http://cmi2.yale.edu ) ) ) [field_field_blog] => Array ( ) [field_field_rss] => Array ( ) [field_field_twitter] => Array ( [0] => Array ( [rendered] => Array ( [#markup] => http://twitter.com/yalecmi2 [#access] => 1 ) [raw] => Array ( [url] => http://twitter.com/yalecmi2 [title] => http://twitter.com/yalecmi2 [attributes] => Array ( ) [display_url] => http://twitter.com/yalecmi2 ) ) ) [field_field_yammer] => Array ( ) [field_field_facebook] => Array ( ) [field_field_flickr] => Array ( ) [field_field_youtube] => Array ( ) )
(sorry about that ugliness!)
How the heck do I pull out that [url] variable?! Ideally, I just want to assign that one value to another variable or just print it out.
If it's helpful, this is from a Drupal 7 view with the Views PHP module.
Thanks!
I recommend reading up about PHP arrays and objects since what you are trying to do is so trivial.
http://php.net/manual/en/language.types.array.php
http://php.net/manual/en/sdo.sample.getset.php