title: Converting json output from twitter search api to an associative array
body: <p>I have the following code that searches for tweets with the hashtag "baseball".</p>
  
  <pre><code>&lt;?php
  echo "&lt;h2&gt;Simple Twitter API Test&lt;/h2&gt;";
  
  require_once('TwitterAPIExchange.php');
  
  /** Set access tokens here - see: https://dev.twitter.com/apps/ **/
  $settings = array(
      'oauth_access_token' =&gt; "*****",
      'oauth_access_token_secret' =&gt; "*****",
      'consumer_key' =&gt; "****",
      'consumer_secret' =&gt; "*****"
  );
  $url = 'https://api.twitter.com/1.1/search/tweets.json';
  $requestMethod = 'GET';
  $getfield = '?q=#baseball';
  $twitter = new TwitterAPIExchange($settings);
  $string = json_decode($twitter-&gt;setGetfield($getfield)
  -&gt;buildOauth($url, $requestMethod)
  -&gt;performRequest(),$assoc = TRUE);
  echo "&lt;pre&gt;";
  print_r($string);
  echo "&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>The output that i am getting is of the form : </p>
  
  <p>Simple Twitter API Test</p>
  
  <pre><code>Array
  (
      [statuses] =&gt; Array
          (
              [0] =&gt; Array
                  (
                      [metadata] =&gt; Array
                          (
                              [result_type] =&gt; recent
                              [iso_language_code] =&gt; en
                          )
                  [created_at] =&gt; Sun Feb 23 22:06:36 +0000 2014
                  [id] =&gt; 4.37710107788E+17
                  [id_str] =&gt; 437710107787657216
                  [text] =&gt; Good day at practice #springtraining #baseball http://t.co/Zu8zJ6qAeI
                  [source] =&gt; Instagram
                  [truncated] =&gt; 
                  [in_reply_to_status_id] =&gt; 
                  [in_reply_to_status_id_str] =&gt; 
                  [in_reply_to_user_id] =&gt; 
                  [in_reply_to_user_id_str] =&gt; 
                  [in_reply_to_screen_name] =&gt; 
                  [user] =&gt; Array
                      (
                          [id] =&gt; 75486410
                          [id_str] =&gt; 75486410
                          [name] =&gt; Jimi Mosher
                          [screen_name] =&gt; zortyonroids
                          [location] =&gt; 
                          [description] =&gt; 
                          [url] =&gt; 
                          [entities] =&gt; Array
                              (
                                  [description] =&gt; Array
                                      (
                                          [urls] =&gt; Array
                                              (
                                              )
  
                                      )
  
                              )
  
                          [protected] =&gt; 
                          [followers_count] =&gt; 12
                          [friends_count] =&gt; 161
                          [listed_count] =&gt; 0
                          [created_at] =&gt; Sat Sep 19 05:58:13 +0000 2009
                          [favourites_count] =&gt; 6
                          [utc_offset] =&gt; 
                          [time_zone] =&gt; 
                          [geo_enabled] =&gt; 1
                          [verified] =&gt; 
                          [statuses_count] =&gt; 50
                          [lang] =&gt; en
                          [contributors_enabled] =&gt; 
                          [is_translator] =&gt; 
                          [is_translation_enabled] =&gt; 
                          [profile_background_color] =&gt; C0DEED
                          [profile_background_image_url] =&gt; http://abs.twimg.com/images/themes/theme1/bg.png
                          [profile_background_image_url_https] =&gt; https://abs.twimg.com/images/themes/theme1/bg.png
                          [profile_background_tile] =&gt; 
                          [profile_image_url] =&gt; http://pbs.twimg.com/profile_images/378800000476940795/6c5ab18350233a756b9980dd2a2e84c1_normal.jpeg
                          [profile_image_url_https] =&gt; https://pbs.twimg.com/profile_images/378800000476940795/6c5ab18350233a756b9980dd2a2e84c1_normal.jpeg
                          [profile_banner_url] =&gt; https://pbs.twimg.com/profile_banners/75486410/1379568136
                          [profile_link_color] =&gt; 0084B4
                          [profile_sidebar_border_color] =&gt; C0DEED
                          [profile_sidebar_fill_color] =&gt; DDEEF6
                          [profile_text_color] =&gt; 333333
                          [profile_use_background_image] =&gt; 1
                          [default_profile] =&gt; 1
                          [default_profile_image] =&gt; 
                          [following] =&gt; 
                          [follow_request_sent] =&gt; 
                          [notifications] =&gt; 
                      )
  
                  [geo] =&gt; 
                  [coordinates] =&gt; 
                  [place] =&gt; 
                  [contributors] =&gt; 
                  [retweet_count] =&gt; 0
                  [favorite_count] =&gt; 0
                  [entities] =&gt; Array
                      (
                          [hashtags] =&gt; Array
                              (
                                  [0] =&gt; Array
                                      (
                                          [text] =&gt; springtraining
                                          [indices] =&gt; Array
                                              (
                                                  [0] =&gt; 21
                                                  [1] =&gt; 36
                                              )
  
                                      )
  
                                  [1] =&gt; Array
                                      (
                                          [text] =&gt; baseball
                                          [indices] =&gt; Array
                                              (
                                                  [0] =&gt; 37
                                                  [1] =&gt; 46
                                              )
  
                                      )
  
                              )
  
                          [symbols] =&gt; Array
                              (
                              )
  
                          [urls] =&gt; Array
                              (
                                  [0] =&gt; Array
                                      (
                                          [url] =&gt; http://t.co/Zu8zJ6qAeI
                                          [expanded_url] =&gt; http://instagram.com/p/kxlYF0yvfD/
                                          [display_url] =&gt; instagram.com/p/kxlYF0yvfD/
                                          [indices] =&gt; Array
                                              (
                                                  [0] =&gt; 47
                                                  [1] =&gt; 69
                                              )
  
                                      )
  
                              )
  
                          [user_mentions] =&gt; Array
                              (
                              )
  
                      )
  
                  [favorited] =&gt; 
                  [retweeted] =&gt; 
                  [possibly_sensitive] =&gt; 
                  [lang] =&gt; en
              )
  </code></pre>
  
  <p>I would like to print only the 'text' as well as the 'created at' fields
  .
  I am unable to decode json into an associative array and print it using the following code:</p>
  
  <pre><code>$string = json_decode($twitter-&gt;setGetfield($getfield)
  -&gt;buildOauth($url, $requestMethod)
  -&gt;performRequest(),$assoc = TRUE);
  foreach($string as $items)
      {
          echo "Time and Date of Tweet: ".$items['created_at']."&lt;br /&gt;";
          echo "Tweet: ". $items['text']."&lt;br /&gt;";
          echo "Tweeted by: ". $items['user']['name']."&lt;br /&gt;";
          echo "Screen name: ". $items['user']['screen_name']."&lt;br /&gt;";
          echo "Followers: ". $items['user']['followers_count']."&lt;br /&gt;";
          echo "Friends: ". $items['user']['friends_count']."&lt;br /&gt;";
          echo "Listed: ". $items['user']['listed_count']."&lt;br /&gt;&lt;hr /&gt;";
      }
  </code></pre>
  
  <p>Please suggest as to what changes should be made to print the associative array.</p>