title: adding an element to a json array in php
body: <p>I have an array of json data :</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 21:50:00 +0000 2014
          [id] =&gt; 4.3770592875932E+17
          [id_str] =&gt; 437705928759320577
          [text] =&gt; 2 new iPhone leads have just broken within 5 minutes of each. What are the odds of that?! No phone for a few days then!!!!
          [source] =&gt; Twitter for iPad
          [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; 221418717
                  [id_str] =&gt; 221418717
                  [name] =&gt; Craig Price
                  [screen_name] =&gt; CraigPrice1
                  [location] =&gt; Glanamman
                  [description] =&gt; Beer &amp; Sport!
                  [url] =&gt; 
                  [entities] =&gt; Array
                      (
                          [description] =&gt; Array
                              (
                                  [urls] =&gt; Array
                                      (
                                      )
  
                              )
  
                      )
  
                  [protected] =&gt; 
                  [followers_count] =&gt; 269
                  [friends_count] =&gt; 765
                  [listed_count] =&gt; 1
                  [created_at] =&gt; Tue Nov 30 16:28:40 +0000 2010
                  [favourites_count] =&gt; 520
                  [utc_offset] =&gt; 0
                  [time_zone] =&gt; London
                  [geo_enabled] =&gt; 1
                  [verified] =&gt; 
                  [statuses_count] =&gt; 2852
                  [lang] =&gt; en
                  [contributors_enabled] =&gt; 
                  [is_translator] =&gt; 
                  [is_translation_enabled] =&gt; 
                  [profile_background_color] =&gt; 0F0F0F
                  [profile_background_image_url] =&gt; http://abs.twimg.com/images/themes/theme15/bg.png
                  [profile_background_image_url_https] =&gt; https://abs.twimg.com/images/themes/theme15/bg.png
                  [profile_background_tile] =&gt; 1
                  [profile_image_url] =&gt; http://pbs.twimg.com/profile_images/435485486153756672/cSzrw5eX_normal.jpeg
                  [profile_image_url_https] =&gt; https://pbs.twimg.com/profile_images/435485486153756672/cSzrw5eX_normal.jpeg
                  [profile_banner_url] =&gt; https://pbs.twimg.com/profile_banners/221418717/1392662771
                  [profile_link_color] =&gt; FA0000
                  [profile_sidebar_border_color] =&gt; EB0000
                  [profile_sidebar_fill_color] =&gt; C0DFEC
                  [profile_text_color] =&gt; 333333
                  [profile_use_background_image] =&gt; 1
                  [default_profile] =&gt; 
                  [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
                      (
                      )
  
                  [symbols] =&gt; Array
                      (
                      )
  
                  [urls] =&gt; Array
                      (
                      )
  
                  [user_mentions] =&gt; Array
                      (
                      )
  
              )
  
          [favorited] =&gt; 
          [retweeted] =&gt; 
          [lang] =&gt; en
      )
  
  [1] =&gt; Array
      (
          [metadata] =&gt; Array
              (
                  [result_type] =&gt; recent
                  [iso_language_code] =&gt; en
              )
  
          [created_at] =&gt; Sun Feb 23 21:26:01 +0000 2014
          [id] =&gt; 4.3769989372629E+17
          [id_str] =&gt; 437699893726289920
          [text] =&gt; @Mogz1457 how about a broken IPhone 3 eh?
          [source] =&gt; Twitter for iPhone
          [truncated] =&gt; 
          [in_reply_to_status_id] =&gt; 4.3757491419192E+17
          [in_reply_to_status_id_str] =&gt; 437574914191917056
          [in_reply_to_user_id] =&gt; 347149526
          [in_reply_to_user_id_str] =&gt; 347149526
          [in_reply_to_screen_name] =&gt; Mogz1457
          [user] =&gt; Array
              (
                  [id] =&gt; 2353482857
                  [id_str] =&gt; 2353482857
                  [name] =&gt; Gwilym McCann
                  [screen_name] =&gt; theBigg_Mac
                  [location] =&gt; Cymru/Wales
                  [description] =&gt; The original Big Mac
                  [url] =&gt; 
                  [entities] =&gt; Array
                      (
                          [description] =&gt; Array
                              (
                                  [urls] =&gt; Array
                                      (
                                      )
  
                              )
  
                      )
  
                  [protected] =&gt; 
                  [followers_count] =&gt; 5
                  [friends_count] =&gt; 6
                  [listed_count] =&gt; 0
                  [created_at] =&gt; Wed Feb 19 23:31:15 +0000 2014
                  [favourites_count] =&gt; 1
                  [utc_offset] =&gt; 
                  [time_zone] =&gt; 
                  [geo_enabled] =&gt; 
                  [verified] =&gt; 
                  [statuses_count] =&gt; 3
                  [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://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png
                  [profile_image_url_https] =&gt; https://abs.twimg.com/sticky/default_profile_images/default_profile_5_normal.png
                  [profile_banner_url] =&gt; https://pbs.twimg.com/profile_banners/2353482857/1392853158
                  [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; 1
                  [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
                      (
                      )
  
                  [symbols] =&gt; Array
                      (
                      )
  
                  [urls] =&gt; Array
                      (
                      )
  
                  [user_mentions] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [screen_name] =&gt; Mogz1457
                                  [name] =&gt; Morgan Williams
                                  [id] =&gt; 347149526
                                  [id_str] =&gt; 347149526
                                  [indices] =&gt; Array
                                      (
                                          [0] =&gt; 0
                                          [1] =&gt; 9
                                      )
  
                              )
  
                      )
  
              )
  
          [favorited] =&gt; 
          [retweeted] =&gt; 
          [lang] =&gt; en
      )
  </code></pre>
  
  <p>I would like to add an attribute to each element in the array in the user element so it would end up like this</p>
  
  <pre><code>[user] =&gt; Array
          (
              [id] =&gt; 221418717
              [id_str] =&gt; 221418717
              [name] =&gt; Craig Price
              [screen_name] =&gt; CraigPrice1
              [location] =&gt; Glanamman
              [description] =&gt; Beer &amp; Sport!
              [url] =&gt; 
              [entities] =&gt; Array
              ***[selected] =&gt; 0***
                  (
                      [description] =&gt; Array
                          (
                              [urls] =&gt; Array
                                  (
                                  )
  
                          )
  
                  )
  </code></pre>
  
  <p>How would i go about doing this. This is what I came up with but to no avail:</p>
  
  <pre><code>$list = file_get_contents('tweets.json');
  
  $json = json_decode($list, true);
  
      foreach($json as $key =&gt; $val)
  {
     $array[$key]['selected'] = 0;
  }
  </code></pre>