Answer the question
In order to leave comments, you need to log in
How to reach nested array from twitter api response?
Hello! After asking, I got a response. I decoded it and now it looks like this:
Array ( [statuses] => Array ( [0] => Array ( [created_at] => Thu Jan 05 17:37:27 +0000 2017 [id] => 817062470183505925 [id_str] => 817062470183505925 [text] => RT @ErikGriffin: Thank @GAEMS_PGE road life is so much better now! Got my @DestinyTheGame and room service. #nerd https://t.co/P7frCJDZu1 [truncated] => [entities] => Array ( [hashtags] => Array ( [0] => Array ( [text] => nerd [indices] => Array ( [0] => 108 [1] => 113 ) ) ) [symbols] => Array ( ) [user_mentions] => Array ( [0] => Array ( [screen_name] => ErikGriffin [name] => Erik Griffin [id] => 16053405 [id_str] => 16053405 [indices] => Array ( [0] => 3 [1] => 15 ) ) [1] => Array ( [screen_name] => GAEMS_PGE [name] => GAEMS [id] => 148112305 [id_str] => 148112305 [indices] => Array ( [0] => 23 [1] => 33 ) ) [2] => Array ( [screen_name] => DestinyTheGame [name] => Destiny The Game [id] => 948444535 [id_str] => 948444535 [indices] => Array ( [0] => 74 [1] => 89 ) ) ) [urls] => Array ( ) [media] => Array ( [0] => Array ( [id] => 817054192359456768 [id_str] => 817054192359456768 [indices] => Array ( [0] => 114 [1] => 137 ) [media_url] => http://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [media_url_https] => https://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [url] => https://t.co/P7frCJDZu1 [display_url] => pic.twitter.com/P7frCJDZu1 [expanded_url] => https://twitter.com/ErikGriffin/status/817054214165819392/photo/1 [type] => photo [sizes] => Array ( [medium] => Array ( [w] => 900 [h] => 1200 [resize] => fit ) [small] => Array ( [w] => 510 [h] => 680 [resize] => fit ) [thumb] => Array ( [w] => 150 [h] => 150 [resize] => crop ) [large] => Array ( [w] => 1536 [h] => 2048 [resize] => fit ) ) [source_status_id] => 817054214165819392 [source_status_id_str] => 817054214165819392 [source_user_id] => 16053405 [source_user_id_str] => 16053405 ) ) ) [extended_entities] => Array ( [media] => Array ( [0] => Array ( [id] => 817054192359456768 [id_str] => 817054192359456768 [indices] => Array ( [0] => 114 [1] => 137 ) [media_url] => http://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [media_url_https] => https://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [url] => https://t.co/P7frCJDZu1 [display_url] => pic.twitter.com/P7frCJDZu1 [expanded_url] => https://twitter.com/ErikGriffin/status/817054214165819392/photo/1 [type] => photo [sizes] => Array ( [medium] => Array ( [w] => 900 [h] => 1200 [resize] => fit ) [small] => Array ( [w] => 510 [h] => 680 [resize] => fit ) [thumb] => Array ( [w] => 150 [h] => 150 [resize] => crop ) [large] => Array ( [w] => 1536 [h] => 2048 [resize] => fit ) ) [source_status_id] => 817054214165819392 [source_status_id_str] => 817054214165819392 [source_user_id] => 16053405 [source_user_id_str] => 16053405 ) ) ) [metadata] => Array ( [iso_language_code] => en [result_type] => recent ) [source] => Twitter for Android [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => Array ( [id] => 2448946046 [id_str] => 2448946046 [name] => SharlineMarie [screen_name] => SharlineMarle [location] => West Palm [description] => Beneath the Make- Up, and behind the Smile.. Im just a Girl Wishing for the World.. [url] => [entities] => Array ( [description] => Array ( [urls] => Array ( ) ) ) [protected] => [followers_count] => 42 [friends_count] => 1391 [listed_count] => 12 [created_at] => Thu Apr 17 05:02:06 +0000 2014 [favourites_count] => 466 [utc_offset] => -28800 [time_zone] => Pacific Time (US & Canada) [geo_enabled] => [verified] => [statuses_count] => 529 [lang] => en [contributors_enabled] => [is_translator] => [is_translation_enabled] => [profile_background_color] => EDECE9 [profile_background_image_url] => http://abs.twimg.com/images/themes/theme3/bg.gif [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme3/bg.gif [profile_background_tile] => [profile_image_url] => http://pbs.twimg.com/profile_images/770369635690618882/TvzcYa-Q_normal.jpg [profile_image_url_https] => https://pbs.twimg.com/profile_images/770369635690618882/TvzcYa-Q_normal.jpg [profile_banner_url] => https://pbs.twimg.com/profile_banners/2448946046/1472505412 [profile_link_color] => 088253 [profile_sidebar_border_color] => D3D2CF [profile_sidebar_fill_color] => E3E2DE [profile_text_color] => 634047 [profile_use_background_image] => 1 [has_extended_profile] => [default_profile] => [default_profile_image] => [following] => [follow_request_sent] => [notifications] => [translator_type] => none ) [geo] => [coordinates] => [place] => [contributors] => [retweeted_status] => Array ( [created_at] => Thu Jan 05 17:04:39 +0000 2017 [id] => 817054214165819392 [id_str] => 817054214165819392 [text] => Thank @GAEMS_PGE road life is so much better now! Got my @DestinyTheGame and room service. #nerd https://t.co/P7frCJDZu1 [truncated] => [entities] => Array ( [hashtags] => Array ( [0] => Array ( [text] => nerd [indices] => Array ( [0] => 91 [1] => 96 ) ) ) [symbols] => Array ( ) [user_mentions] => Array ( [0] => Array ( [screen_name] => GAEMS_PGE [name] => GAEMS [id] => 148112305 [id_str] => 148112305 [indices] => Array ( [0] => 6 [1] => 16 ) ) [1] => Array ( [screen_name] => DestinyTheGame [name] => Destiny The Game [id] => 948444535 [id_str] => 948444535 [indices] => Array ( [0] => 57 [1] => 72 ) ) ) [urls] => Array ( ) [media] => Array ( [0] => Array ( [id] => 817054192359456768 [id_str] => 817054192359456768 [indices] => Array ( [0] => 97 [1] => 120 ) [media_url] => http://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [media_url_https] => https://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [url] => https://t.co/P7frCJDZu1 [display_url] => pic.twitter.com/P7frCJDZu1 [expanded_url] => https://twitter.com/ErikGriffin/status/817054214165819392/photo/1 [type] => photo [sizes] => Array ( [medium] => Array ( [w] => 900 [h] => 1200 [resize] => fit ) [small] => Array ( [w] => 510 [h] => 680 [resize] => fit ) [thumb] => Array ( [w] => 150 [h] => 150 [resize] => crop ) [large] => Array ( [w] => 1536 [h] => 2048 [resize] => fit ) ) ) ) ) [extended_entities] => Array ( [media] => Array ( [0] => Array ( [id] => 817054192359456768 [id_str] => 817054192359456768 [indices] => Array ( [0] => 97 [1] => 120 ) [media_url] => http://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [media_url_https] => https://pbs.twimg.com/media/C1bCdYHUQAAKEwc.jpg [url] => https://t.co/P7frCJDZu1 [display_url] => pic.twitter.com/P7frCJDZu1 [expanded_url] => https://twitter.com/ErikGriffin/status/817054214165819392/photo/1 [type] => photo [sizes] => Array ( [medium] => Array ( [w] => 900 [h] => 1200 [resize] => fit ) [small] => Array ( [w] => 510 [h] => 680 [resize] => fit ) [thumb] => Array ( [w] => 150 [h] => 150 [resize] => crop ) [large] => Array ( [w] => 1536 [h] => 2048 [resize] => fit ) ) ) ) ) [metadata] => Array ( [iso_language_code] => en [result_type] => recent ) [source] => Twitter for Android [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => Array ( [id] => 16053405 [id_str] => 16053405 [name] => Erik Griffin [screen_name] => ErikGriffin
$tweetsArray = json_decode($response, true);
foreach($tweetsArray['statuses'] as $item) {
echo '<li>'.$item['text'].'</li>'."\n";
}
Answer the question
In order to leave comments, you need to log in
You can mostly get there with a few square brackets:
or
In the first case - we work with both index and associative arrays
, and in the second - only with associative ones. In order to work only with indexes, you can do this:
Answering your question, how to get to hashtags, could you provide the original json in a formatted form in the <code> tag here?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question