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 :)
Related
i get json in my project and then i have replace some sub array of it and again have to pass it. so, when i decode json and display it with pre tag it's display like this.
Array
(
[callid] => 59538ea658dfa
[action] => config_get
[message] => ok
[data] => Array
(
[config_file] => /cf/conf/config.xml
[config] => Array
(
[filter] => Array
(
[separator] => Array
(
[wan] =>
)
[rule] => Array
(
[0] => Array
(
[id] =>
[tracker] => 1498479412
[type] => pass
[interface] => wan
[ipprotocol] => inet
[tag] =>
[tagged] =>
[max] =>
[max-src-nodes] =>
[max-src-conn] =>
[max-src-states] =>
[statetimeout] =>
[statetype] => keep state
[os] =>
[protocol] => tcp
[source] => Array
(
[any] =>
)
[destination] => Array
(
[any] =>
)
[descr] => Hi manoj2
[updated] => Array
(
[time] => 1498479412
[username] => admin#172.16.1.22
)
[created] => Array
(
[time] => 1498479412
[username] => admin#172.16.1.22
)
)
[1] => Array
(
[statetype] => keep state
[statetimeout] =>
[max-src-states] =>
[max] =>
[tagged] =>
[tag] =>
[ipprotocol] => inet
[interface] => wan
[os] =>
[source] => Array
(
[any] =>
)
[destination] => Array
(
[any] =>
)
[descr] => hi Divyesh
[updated] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[created] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[type] => pass
[tracker] => 1498301528
[id] =>
[max-src-nodes] =>
[max-src-conn] =>
)
[2] => Array
(
[destination] => Array
(
[any] =>
)
[source] => Array
(
[network] => lan
)
[tracker] => 0100000101
[interface] => lan
[descr] => Default allow LAN to any rule
[ipprotocol] => inet
[type] => pass
)
[3] => Array
(
[destination] => Array
(
[any] =>
)
[source] => Array
(
[network] => lan
)
[tracker] => 0100000102
[interface] => lan
[descr] => Default allow LAN IPv6 to any rule
[ipprotocol] => inet6
[type] => pass
)
)
)
[shaper] =>
[ipsec] =>
[aliases] => Array
(
[alias] => Array
(
[0] => Array
(
[name] => manoj2_alias2
[type] => network
[address] => manoj2_alias3 172.30.2.65/16 172.30.2.51/32
[descr] => descc
[detail] => nfvbg||dfg||asd | asdfg
)
[1] => Array
(
[name] => manoj2_alias3
[type] => host
[address] => tyuty tyu
[descr] => dess
[detail] => tyu||tyu
)
[2] => Array
(
[name] => sdf
[type] => network
[address] => manoj2_alias2
[descr] => afsasf || weriojdg
[detail] => 256418
)
)
)
)
)
)
and i want to just replace portion sub array of [rule] with the.
[rule] => Array
(
[0] => Array
(
[id] =>
[tracker] => 1498479412
[type] => block
[interface] => lan
[ipprotocol] => any
[tag] =>
[tagged] =>
[max] =>
[max-src-nodes] =>
[max-src-conn] =>
[max-src-states] =>
[statetimeout] =>
[statetype] => keep state
[os] =>
[protocol] => tcp/udp
[source] => Array
(
[any] =>
)
[destination] => Array
(
[any] =>
)
[descr] => second option
[updated] => Array
(
[time] => 149844356
[username] => admin#172.16.1.22
)
[created] => Array
(
[time] => 1498479412
[username] => admin#172.16.1.22
)
)
[1] => Array
(
[statetype] => keep state
[statetimeout] =>
[max-src-states] =>
[max] =>
[tagged] =>
[tag] =>
[ipprotocol] => single
[interface] => wan
[os] =>
[source] => Array
(
[any] => 172.31.2.65/24
)
[destination] => Array
(
[any] => manoj2_alias2
)
[descr] => first option
[updated] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[created] => Array
(
[username] => admin#192.168.1.100
[time] => 1498301528
)
[type] => pass
[tracker] => 1498301528
[id] =>
[max-src-nodes] =>
[max-src-conn] =>
)
)
how to do it please help me. i tried but not any success.
Access your array element and assign the new array to it.
$array['data']['config']['filter']['rule'] = $theNewRuleArray;
Update: I have a solution - please see below for details.
I have an array where the keys are levels (in a navigation tree for example) - something like
Array
(
[0] => Array
(
[100] => Array
(
[name] => foo100
[slug] => foo100
[id] => 100
[parent] => 0
[level] => 0
)
[101] => Array
(
[name] => foo101
[slug] => foo101
[id] => 101
[parent] => 0
[level] => 0
)
)
[1] => Array
(
[200] => Array
(
[name] => foo200
[slug] => foo200
[id] => 200
[parent] => 100
[level] => 1
)
[201] => Array
(
[name] => foo201
[slug] => foo201
[id] => 201
[parent] => 101
[level] => 1
)
)
[2] => Array
(
[300] => Array
(
[name] => foo300
[slug] => foo300
[id] => 300
[parent] => 200
[level] => 2
)
[301] => Array
(
[name] => foo301
[slug] => foo301
[id] => 301
[parent] => 201
[level] => 2
)
)
[3] => Array
(
[400] => Array
(
[name] => foo400
[slug] => foo400
[id] => 400
[parent] => 300
[level] => 3
)
)
[4] => Array
(
[500] => Array
(
[name] => foo500
[slug] => foo500
[id] => 500
[parent] => 400
[level] => 4
)
)
)
I need to create an array from this which iterates from the top most level and creates an array with the key being the slug of that level - to produce the following:
Array
(
[foo500] => Array
(
[4] => Array
(
[name] => foo500
)
[3] => Array
(
[name] => foo400
)
[2] => Array
(
[name] => foo300
)
[1] => Array
(
[name] => foo200
)
[0] => Array
(
[name] => foo100
)
)
[foo400] => Array
(
[3] => Array
(
[name] => foo400
)
[2] => Array
(
[name] => foo300
)
[1] => Array
(
[name] => foo200
)
[0] => Array
(
[name] => foo100
)
)
[foo300] => Array
(
[2] => Array
(
[name] => foo300
)
[1] => Array
(
[name] => foo200
)
[0] => Array
(
[name] => foo100
)
)
[foo301] => Array
(
[2] => Array
(
[name] => foo301
)
[1] => Array
(
[name] => foo201
)
[0] => Array
(
[name] => foo101
)
)
[foo200] => Array
(
[1] => Array
(
[name] => foo200
)
[0] => Array
(
[name] => foo100
)
)
[foo201] => Array
(
[1] => Array
(
[name] => foo201
)
[0] => Array
(
[name] => foo101
)
)
[foo100] => Array
(
[0] => Array
(
[name] => foo100
)
)
[foo101] => Array
(
[0] => Array
(
[name] => foo101
)
)
)
I hope this explains the issue - struggling to get this right! Any help much appreciated!
Update - solution.
For this I removed the first level of keys to leave
Array
(
[107] => Array
(
[id] => 107
[name] => About Us
[indexID] => about
[level] => 0
[parent] => 0
)
[109] => Array
(
[id] => 109
[name] => Home
[indexID] => index
[level] => 0
[parent] => 0
)
}
etc etc
Assuming $data is the above array I went with:
foreach ($data as $k => $v) {
if ($v['parent'] == 0) {
$bc[$v['indexID']][0]['name'] = $v['name'];
$bc[$v['indexID']][0]['indexID'] = $v['indexID'];
}
else {
$nextParent = $v['parent'];
$currentIndexID = $v['indexID'];
$currentName = $v['name'];
$bc[$v['indexID']][0]['name'] = $currentName;
$bc[$v['indexID']][0]['indexID'] = $currentIndexID;
for($i=1;$i<=$level;$i++) {
foreach ($data as $a => $b) {
if ($a == $nextParent) {
$nextParent = $b['parent'];
$bc[$v['indexID']][$i]['name'] = $b['name'];
$bc[$v['indexID']][$i]['indexID'] = $b['indexID'];
}
}
}
}
}
I just started using moltin and learn to developing it.
In the getting started there is code that to show product
<?php
$product = \Product::Find(['slug' => 'baju']);
?>
documentation link https://moltin.com/getting-started/php
and the result is when I print array
<?php
print_r($product);
?>
It shows like this
Array ( [status] => 1 [result] => Array ( [0] => Array ( [id] => 1207658536885027482 [order] => [created_at] => 2016-03-17 03:08:58 [updated_at] => 2016-03-17 03:08:58 [sku] => baju-1 [title] => baju [slug] => baju [sale_price] => 0 [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [category] => Array ( [value] => Uncategorized [data] => Array ( [1134518259857490806] => Array ( [id] => 1134518259857490806 [order] => [created_at] => 2015-12-07 05:12:15 [updated_at] => 2015-12-07 05:12:15 [parent] => [slug] => uncategorized [status] => Array ( [value] => Live [data] => Array ( [key] => 1 [value] => Live ) ) [title] => Uncategorized [description] => Products that do not fit into another category ) ) ) [stock_level] => 10 [stock_status] => Array ( [value] => In Stock [data] => Array ( [key] => 1 [value] => In Stock ) ) [description] => baju [requires_shipping] => Array ( [value] => Yes [data] => Array ( [key] => 1 [value] => Yes ) ) [weight] => 0 [height] => 0 [width] => 0 [depth] => 0 [catalog_only] => Array ( [value] => No [data] => Array ( [key] => 0 [value] => No ) ) [tax_band] => Array ( [value] => Default [data] => Array ( [id] => 1134518260142703561 [title] => Default [description] => [rate] => 20 [created_at] => [updated_at] => ) ) [collection] => [brand] => [price] => Array ( [value] => £1.20 [data] => Array ( [formatted] => Array ( [with_tax] => £1.20 [without_tax] => £1.00 [tax] => £0.20 ) [rounded] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) [raw] => Array ( [with_tax] => 1.2 [without_tax] => 1 [tax] => 0.2 ) ) ) [is_variation] => [modifiers] => Array ( ) [images] => Array ( ) ) ) [pagination] => Array ( [total] => 1 [current] => 1 [limit] => 10 [offset] => 0 [from] => 1 [to] => 1 [offsets] => Array ( [first] => [previous] => [next] => [last] => ) [links] => Array ( [first] => [previous] => [next] => [last] => ) ) ) status = 1
How to get specific array from this list?
I already try
<?php
echo $product[0]['id'];
?>
it didn't work, show error Notice: Undefined offset: 0
you have a multidimensional array under the result key
access it the following way:
$product['result'][0]['id']
Give this a try:
echo $product['result'][0]['id'];
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;
}
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