How can we store protected array values in php variables - php

I am trying to access a protected array tree. I had tried many ways to get the data from the tree. The array is stored in a variable called $printers. I had tried a normal approach like using array index values like echo $printers[0].printers etc, but no luck. Could anyone please guide me to how to access this protected array tree?
Array
(
[0] => PrintNode\Printer Object
(
[id:protected] => 69416933
[computer:protected] => PrintNode\Computer Object
(
[id:protected] => 123456
[name:protected] => DESKTOP
[inet:protected] => 0.0.0.0
[inet6:protected] =>
[hostname:protected] => Controlroom#DESKTOP
[version:protected] => 4.23.1
[jre:protected] =>
[systemInfo:protected] =>
[acceptOfflinePrintJobs:protected] =>
[createTimestamp:protected] => DateTime Object
(
[date] => 2020-04-16 11:23:56.595000
[timezone_type] => 2
[timezone] => Z
)
[state:protected] => connected
)
[name:protected] => ZJ
[description:protected] => ZJ-80 11.3.0.1
[capabilities:protected] => Array
(
[bins] => Array
(
[0] => Automatically Select
[1] => Manual Paper Feed
)
[collate] => 1
[color] =>
[copies] => 9999
[dpis] => Array
(
[0] => 203x203
)
[duplex] =>
[extent] => Array
(
[0] => Array
(
[0] => 719
[1] => 2099
)
[1] => Array
(
[0] => 719
[1] => 32759
)
)
[medias] => Array
(
)
[nup] => Array
(
[0] => 1
[1] => 2
[2] => 4
[3] => 6
[4] => 9
[5] => 16
)
[papers] => Array
(
[ZPrinter Paper(80 x 210mm)] => Array
(
[0] => 719
[1] => 2099
)
[ZPrinter Paper(80 x 297mm)] => Array
(
[0] => 719
[1] => 2970
)
[ZPrinter Paper(80 x 3276mm)] => Array
(
[0] => 719
[1] => 32759
)
[ZPrinter Paper(80(72) x 210mm)] => Array
(
[0] => 719
[1] => 2099
)
[ZPrinter Paper(80(72) x 297mm)] => Array
(
[0] => 719
[1] => 2970
)
[ZPrinter Paper(80(72) x 3276mm)] => Array
(
[0] => 719
[1] => 32759
)
)
[printrate] =>
[supports_custom_paper_size] =>
)
[default:protected] =>
[createTimestamp:protected] => DateTime Object
(
[date] => 2020-04-29 13:53:39.527000
[timezone_type] => 2
[timezone] => Z
)
[state:protected] => offline
)
[1] => PrintNode\Printer Object
(
[id:protected] => 123456789
[computer:protected] => PrintNode\Computer Object
(
[id:protected] => 1234566
[name:protected] => DESKTOP
[inet:protected] => 192.168.1.2
[inet6:protected] =>
[hostname:protected] => Controlroom#DESKTOP
[version:protected] => 4.23.1
[jre:protected] =>
[systemInfo:protected] =>
[acceptOfflinePrintJobs:protected] =>
[createTimestamp:protected] => DateTime Object
(
[date] => 2020-04-16 11:23:56.595000
[timezone_type] => 2
[timezone] => Z
)
[state:protected] => connected
)
[name:protected] => ZJ-80(copy of 2)
[description:protected] => ZJ-80 11.3.0.1
[capabilities:protected] => Array
(
[bins] => Array
(
[0] => Automatically Select
[1] => Manual Paper Feed
)
[collate] => 1
[color] =>
[copies] => 9999
[dpis] => Array
(
[0] => 203x203
)
[duplex] =>
[extent] => Array
(
[0] => Array
(
[0] => 719
[1] => 2099
)
[1] => Array
(
[0] => 719
[1] => 32759
)
)
[medias] => Array
(
)
[nup] => Array
(
[0] => 1
[1] => 2
[2] => 4
[3] => 6
[4] => 9
[5] => 16
)
[papers] => Array
(
[ZPrinter Paper(80 x 210mm)] => Array
(
[0] => 719
[1] => 2099
)
[ZPrinter Paper(80 x 297mm)] => Array
(
[0] => 719
[1] => 2970
)
[ZPrinter Paper(80 x 3276mm)] => Array
(
[0] => 719
[1] => 32759
)
[ZPrinter Paper(80(72) x 210mm)] => Array
(
[0] => 719
[1] => 2099
)
[ZPrinter Paper(80(72) x 297mm)] => Array
(
[0] => 719
[1] => 2970
)
[ZPrinter Paper(80(72) x 3276mm)] => Array
(
[0] => 719
[1] => 32759
)
)
[printrate] =>
[supports_custom_paper_size] =>
)
[default:protected] => 1
[createTimestamp:protected] => DateTime Object
(
[date] => 2020-04-29 14:34:00.787000
[timezone_type] => 2
[timezone] => Z
)
[state:protected] => offline
)
)
I need to access the values, the hostname:protected and name:protected and paper's 1st element.

Related

How can I get a specific item from a multidimensional array (php)?

How can I get the specific item from the following array. I'd like to get the close values.
What should I do in this case?
$data = json_decode(file_get_contents($req_url),true);
// print_r($data); //give the following array;
// Array ( [chart] => Array ( [result] => Array ( [0] => Array ( [meta] => Array ( [currency] => USD [symbol] => SEAS [exchangeName] => NYQ [instrumentType] => EQUITY [firstTradeDate] => 1366378200 [regularMarketTime] => 1588622401 [gmtoffset] => -14400 [timezone] => EDT [exchangeTimezoneName] => America/New_York [regularMarketPrice] => 14.55 [chartPreviousClose] => 14.11 [previousClose] => 14.11 [scale] => 3 [priceHint] => 2 [currentTradingPeriod] => Array ( [pre] => Array ( [timezone] => EDT [end] => 1588599000 [start] => 1588579200 [gmtoffset] => -14400 ) [regular] => Array ( [timezone] => EDT [end] => 1588622400 [start] => 1588599000 [gmtoffset] => -14400 ) [post] => Array ( [timezone] => EDT [end] => 1588636800 [start] => 1588622400 [gmtoffset] => -14400 ) ) [tradingPeriods] => Array ( [0] => Array ( [0] => Array ( [timezone] => EDT [end] => 1588622400 [start] => 1588599000 [gmtoffset] => -14400 ) ) ) [dataGranularity] => 5m [range] => 1d [validRanges] => Array ( [0] => 1d [1] => 5d [2] => 1mo [3] => 3mo [4] => 6mo [5] => 1y [6] => 2y [7] => 5y [8] => 10y [9] => ytd [10] => max ) ) [timestamp] => Array ( [0] => 1588599000 [1] => 1588599300 [2] => 1588599600 [3] => 1588599900 [4] => 1588600200 [5] => 1588600500 ) [indicators] => Array ( [quote] => Array ( [0] => Array ( [open] => Array ( [0] => 13.3599996567 [1] => 13.8599996567 [2] => 13.720000267 [3] => 13.8800001144 [4] => 14.0349998474 [5] => 14.051199913 ) [close] => Array ( [0] => 13.9499998093 [1] => 13.7299995422 [2] => 13.8400001526 [3] => 14.0450000763 [4] => 14.0600004196 [5] => 14.1899995804 ) [high] => Array ( [0] => 14 [1] => 13.8599996567 [2] => 13.9399995804 [3] => 14.0900001526 [4] => 14.1000003815 [5] => 14.2600002289 ) [low] => Array ( [0] => 13.1099996567 [1] => 13.5900001526 [2] => 13.720000267 [3] => 13.8699998856 [4] => 13.8509998322 [5] => 14 ) [volume] => Array ( [0] => 124733 [1] => 49489 [2] => 51657 [3] => 48362 [4] => 34055 [5] => 36566 ) ) ) ) ) ) [error] => ) );
$close= $data['chart']['result']['indicators']['close'] ;
echo $close;
For your Array:
Array ( [chart] =>
Array ( [result] =>
Array ( [0] =>
Array ( [meta] =>
Array ( [currency] => USD [symbol] => SEAS [exchangeName] => NYQ [instrumentType] => EQUITY [firstTradeDate] => 1366378200 [regularMarketTime] => 1588622401 [gmtoffset] => -14400 [timezone] => EDT [exchangeTimezoneName] => America/New_York [regularMarketPrice] => 14.55 [chartPreviousClose] => 14.11 [previousClose] => 14.11 [scale] => 3 [priceHint] => 2 [currentTradingPeriod] =>
Array ( [pre] =>
Array ( [timezone] => EDT [end] => 1588599000 [start] => 1588579200 [gmtoffset] => -14400 ) [regular] =>
Array ( [timezone] => EDT [end] => 1588622400 [start] => 1588599000 [gmtoffset] => -14400 ) [post] =>
Array ( [timezone] => EDT [end] => 1588636800 [start] => 1588622400 [gmtoffset] => -14400 ) ) [tradingPeriods] =>
Array ( [0] =>
Array ( [0] =>
Array ( [timezone] => EDT [end] => 1588622400 [start] => 1588599000 [gmtoffset] => -14400 ) ) ) [dataGranularity] => 5m [range] => 1d [validRanges] =>
Array ( [0] => 1d [1] => 5d [2] => 1mo [3] => 3mo [4] => 6mo [5] => 1y [6] => 2y [7] => 5y [8] => 10y [9] => ytd [10] => max ) ) [timestamp] =>
Array ( [0] => 1588599000 [1] => 1588599300 [2] => 1588599600 [3] => 1588599900 [4] => 1588600200 [5] => 1588600500 ) [indicators] =>
Array ( [quote] =>
Array ( [0] =>
Array ( [open] =>
Array ( [0] => 13.3599996567 [1] => 13.8599996567 [2] => 13.720000267 [3] => 13.8800001144 [4] => 14.0349998474 [5] => 14.051199913 ) [close] =>
Array ( [0] => 13.9499998093 [1] => 13.7299995422 [2] => 13.8400001526 [3] => 14.0450000763 [4] => 14.0600004196 [5] => 14.1899995804 ) [high] =>
Array ( [0] => 14 [1] => 13.8599996567 [2] => 13.9399995804 [3] => 14.0900001526 [4] => 14.1000003815 [5] => 14.2600002289 ) [low] =>
Array ( [0] => 13.1099996567 [1] => 13.5900001526 [2] => 13.720000267 [3] => 13.8699998856 [4] => 13.8509998322 [5] => 14 ) [volume] =>
Array ( [0] => 124733 [1] => 49489 [2] => 51657 [3] => 48362 [4] => 34055 [5] => 36566 ) ) ) ) ) ) [error] => ) );
You need:
<?php
$data = json_decode(file_get_contents($req_url),true);
$close = $data['chart']['result'][0]['meta']['currentTradingPeriod']['pre']['regular']['post']['tradingPeriods'][0][0]['validRanges']['timestamp']['indicators']['quote'][0]['open']['close'];
echo $close;
?>
UPDATE: Your comment shows different array. You need:
<?php
$req_url = 'https://query1.finance.yahoo.com/v7/finance/chart/SEAS?&interval=5m';
$data = json_decode(file_get_contents($req_url), true);
$close = $data['chart']['result'][0]['indicators']['quote'][0]['close'];
print_r($close);
?>

Unset values from a multidimensional array from object

How can I unset all the setsystemtime elements from this array?
It's php version 4.4
This is the output of an instance inside my code:
2016-10-19T00:54:41-04:00 INFO (6): Array
(
[ * _bootstrap] => Bootstrap Object
(
[_appNamespace:protected] =>
[_resourceLoader:protected] =>
[_application:protected] => PEP_Application Object
(
[_autoloader:protected] => PEP_Autoloader Object
(
[_defaultAutoloader:protected] => Array
(
[0] => PEP_Loader
[1] => loadClass
)
[_fallbackAutoloader:protected] =>
[_internalAutoloader:protected] => Array
(
[0] => PEP_Autoloader Object
*RECURSION*
[1] => _autoload
)
[_namespaces:protected] => Array
(
[Zend_] => 1
[ZendX_] => 1
[WDPRO_] => 1
[PEP_] => 1
[controllers_helpers_] => 1
[Guzzle] => 1
[Symfony] => 1
)
[_suppressNotFoundWarnings:protected] =>
[_zfPath:protected] =>
)
[_bootstrap:protected] => Bootstrap Object
*RECURSION*
[_environment:protected] => local
[_optionKeys:protected] => Array
(
[0] => phpsettings
[1] => includepaths
[2] => bootstrap
[3] => resources
[4] => deviceprofiling
[5] => pluginpaths
[6] => autoloadernamespaces
)
[_options:protected] => Array
(
[resources] => Array
(
[frontController] => Array
(
[controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers
[moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules
)
[layout] => Array
(
[layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts
)
[setsystemtime] => Array
(
[load] => 1
)
[session] => Array
(
[strict] => 1
)
[modules] => Array
(
[0] => api
[1] => trip
[2] => tickets
[3] => events
[4] => passes
[5] => plan
[6] => resortaddons
[7] => debugutils
[8] => visa-instant-credit
)
[view] =>
[log] => Array
(
[logConfig] => /configs/log.ini
)
[stats] => Array
(
[serviceLogLevel] => INFO
[requestResponseLogLevel] => DEBUG
[viewLogLevel] => INFO
[actionLogLevel] => INFO
[appLogLevel] => INFO
[memoryLogLevel] => DEBUG
)
[serviceSuccessLog] => Array
(
[logConfig] => /configs/serviceSuccessLog.ini
)
)
[deviceprofiling] => Array
(
[cookieName] => WDPROView
[timeToLive] => 604800
[cookiePath] => /
[enabled] => 1
[routeBlackList] => Array
(
[0] => /api
[1] => /utils
)
)
[pluginpaths] => Array
(
[PEP_Stats_Resource_] => PEP/Stats/Resource
[PEP_Application_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library/PEP/Application/Resource
[Default_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/resource
)
[autoloadernamespaces] => Array
(
[0] => WDPRO_
[1] => Zend_
[2] => PEP_
[3] => controllers_helpers_
[4] => Guzzle
[5] => Symfony
)
)
)
[_environment:protected] =>
[_optionKeys:protected] => Array
(
[0] => phpsettings
[1] => includepaths
[2] => bootstrap
[3] => resources
[4] => deviceprofiling
[5] => pluginpaths
[6] => autoloadernamespaces
)
[_options:protected] => Array
(
[phpSettings] => Array
(
[log_errors] => 1
[date] => Array
(
[timezone] => America/New_York
)
[display_startup_errors] => 0
[display_errors] => 1
[error_reporting] => 32767
[error_log] => C:\LodgingPhp\com-ui-php\target/logs/php_error.log
)
[includePaths] => Array
(
[library] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library
)
[bootstrap] => Array
(
[path] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/Bootstrap.php
[class] => Bootstrap
)
[resources] => Array
(
[frontController] => Array
(
[controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers
[moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules
)
[layout] => Array
(
[layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts
)
[setsystemtime] => Array
(
[load] => 1
)
[session] => Array
(
[strict] => 1
)
[modules] => Array
(
[0] => api
[1] => trip
[2] => tickets
[3] => events
[4] => passes
[5] => plan
[6] => resortaddons
[7] => debugutils
[8] => visa-instant-credit
)
[view] =>
[log] => Array
(
[logConfig] => /configs/log.ini
)
[stats] => Array
(
[serviceLogLevel] => INFO
[requestResponseLogLevel] => DEBUG
[viewLogLevel] => INFO
[actionLogLevel] => INFO
[appLogLevel] => INFO
[memoryLogLevel] => DEBUG
)
[serviceSuccessLog] => Array
(
[logConfig] => /configs/serviceSuccessLog.ini
)
)
[deviceprofiling] => Array
(
[cookieName] => WDPROView
[timeToLive] => 604800
[cookiePath] => /
[enabled] => 1
[routeBlackList] => Array
(
[0] => /api
[1] => /utils
)
)
[pluginpaths] => Array
(
[PEP_Stats_Resource_] => PEP/Stats/Resource
[PEP_Application_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/../library/PEP/Application/Resource
[Default_Resource_] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/resource
)
[autoloadernamespaces] => Array
(
[0] => WDPRO_
[1] => Zend_
[2] => PEP_
[3] => controllers_helpers_
[4] => Guzzle
[5] => Symfony
)
)
[_pluginLoader:protected] =>
[_pluginResources:protected] => Array
(
[layout] => Array
(
[layoutPath] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/layouts/scripts
)
[setsystemtime] => Array
(
[load] => 1
)
[session] => Array
(
[strict] => 1
)
[modules] => Array
(
[0] => api
[1] => trip
[2] => tickets
[3] => events
[4] => passes
[5] => plan
[6] => resortaddons
[7] => debugutils
[8] => visa-instant-credit
)
[view] =>
[log] => Array
(
[logConfig] => /configs/log.ini
)
[stats] => Array
(
[serviceLogLevel] => INFO
[requestResponseLogLevel] => DEBUG
[viewLogLevel] => INFO
[actionLogLevel] => INFO
[appLogLevel] => INFO
[memoryLogLevel] => DEBUG
)
[serviceSuccessLog] => Array
(
[logConfig] => /configs/serviceSuccessLog.ini
)
[frontcontroller] => Zend_Application_Resource_Frontcontroller Object
(
[_front:protected] =>
[_bootstrap:protected] => Bootstrap Object
*RECURSION*
[_options:protected] => Array
(
[controllerDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/controllers
[moduleDirectory] => C:\LodgingPhp\com-ui-php\target\packaged-application\application/modules
)
[_skipOptions:protected] => Array
(
[0] => options
[1] => config
)
)
)
[_run:protected] => Array
(
[0] => autoload
)
[_started:protected] => Array
(
[core] => 1
)
)
[ * _options] => Array
(
)
[ * _skipOptions] => Array
(
[0] => options
[1] => config
)
)
I tried with something like this and some variations for unset doesn't make the work... any idea?
foreach($a as $key => $b)
{
if($b == 'setsystemtime')
{
unset($a[$key]);
}
}
Looking for other answers I also try this:
foreach (array_keys($a, 'setsystemtime' , true) as $key) {
$logger->info('encontro a setsystem time!!!!!');
unset($a[$key]);
}
But never enters on it.
Thanks all!!

How to sort object array by value deep inside array

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 access the facebook books.reads's title using php?

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 :)

retrieving data from a php object

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

Categories