I am getting following output from running a php code, now i want to get "url" field from the following array, how can i get this?
Array (
[data] => Array (
[0] => Array (
[id] => xxxxx
[from] => Array (
[id] => xxxxxx
[name] => abc
)
[start_time] => 2012-04-28T07:49:17+0000
[end_time] => 2012-04-28T07:49:17+0000
[publish_time] => 2012-04-28T07:49:17+0000
[application] => Array (
[id] => 389407107765872
[name] => Ki News Social Reader
)
[data] => Array (
[article] => Array (
[id] => 10150703062718596
[url] => http://example.com
[type] => kinewssocialreader:article
[title] => story
)
)
Thanks in advance!
Index it like any other array. Looking at the actual source of print_r
can be much more helpful than seeing it all strung together in one line.
$arr['data'][0]['data']['article']['url']
Use this
$array['data'][0]['data']['article']['url']
if your array variable is called $array.
If you want to access the array with its key:
$array["key_name"] , $array[$key_name]
If you want to access the array with its element order:
$array[0], $array[1]
If the result of the selection is array, you can continue to use [] to go deeper:
Assume $array["key"] is containing an array, and the array has "another_key" keyed value;
$array["key"]["another_key"]
will work too.
Assuming that I'm reading the data structure correctly, it would be:
$variableName['data'][0]['data']['article']['url']
Where $variableName is the name of the top level array. The parentheses don't balance, so I can't be 100% sure of the structure.
I've drawn out the structure to look like this. If this matches your structure, the naming above will work.
Array (
[data] => Array (
[0] => Array (
[id] => xxxxx
[from] => Array (
[id] => xxxxxx
[name] => abc
)
[start_time] => 2012-04-28T07:49:17+0000
[end_time] => 2012-04-28T07:49:17+0000
[publish_time] => 2012-04-28T07:49:17+0000
[application] => Array (
[id] => 389407107765872
[name] => Ki News Social Reader
)
[data] => Array (
[article] => Array (
[id] => 10150703062718596
[url] => http://example.com
[type] => kinewssocialreader:article [title] => story
)
)
)
)
)
$url=$myArray['data'][0]['data']['article']['url']; //assuming $myArray is array