Can anyone please help me out with that one. I’m getting the locale of Facebook page fans. The output from Facebook is in JSON format. After I json_decode($fb_output) I end up with array below. I’d like to echo a list with the top 10 languages (or all if there are less than 10) and the value in the key(number of people who speak that language). So far I’ve unsuccessfully tried to get it with foreach ($fb_output $key => $value)
Here is the array:
Array (
[0] => stdClass Object (
[value] => stdClass Object (
[de_DE] => 8527
[en_US] => 313
[en_GB] => 147
[tr_TR] => 106
[it_IT] => 79
[sr_RS] => 25
[hu_HU] => 24
[es_ES] => 15
[bs_BA] => 12
[es_LA] => 12
[sk_SK] => 11
[ro_RO] => 10
[ru_RU] => 9
[pt_BR] => 9
[nl_NL] => 8
[hr_HR] => 8
[fr_FR] => 7
[sv_SE] => 5
[cs_CZ] => 5
[bg_BG] => 5
)
[end_time] => 2012-03-05T08:00:00+0000 ) )
The number of keys in this array varies from user to user so it’d need to be flexible.
How about something like this:
What it does:
(array)operator)array_keys()function)array_slice()function)If you want to extract the top ten including their values, skip the
array_keyspart and make sure, that the keys of the array don’t get mixed up while slicing it (4th parameter of that function, see the docs for more information):