title: PHP Extract key values from nested arrays
body: <p>I have an API call that returns the following array.  What I'm trying to do in PHP is grab the key values for ONLY the objects in the [by_category] array.  I want to display only the category name and the value for views for that array.  But I'm stuck on how to loop through these nested arrays to get at only those values, ignoring everything in the [by_date] array.  Any tips on where to start?  Any example code I can fiddle with?</p>
  
  <pre><code>Array
  (
      [by_date] =&gt; Array
       (
          [0] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-11-10
                  [views] =&gt; 1202
                  [participations] =&gt; 29
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-09-10
                  [views] =&gt; 2068
                  [participations] =&gt; 66
              )
  
          [2] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-11-14
                  [views] =&gt; 1760
                  [participations] =&gt; 41
              )
  
          [3] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2017-01-01
                  [views] =&gt; 122
                  [participations] =&gt; 3
              )
  
          [4] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-10-06
                  [views] =&gt; 2113
                  [participations] =&gt; 102
              )
  
          [5] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-08-31
                  [views] =&gt; 1986
                  [participations] =&gt; 110
              )
  
          [6] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-07-26
                  [views] =&gt; 127
                  [participations] =&gt; 3
              )
  
          [7] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-12-03
                  [views] =&gt; 826
                  [participations] =&gt; 24
              )
  
          [8] =&gt; Array
              (
                  [id] =&gt; 
                  [date] =&gt; 2016-11-13
                  [views] =&gt; 796
                  [participations] =&gt; 20
              )
  
      )
  
  [by_category] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; announcements
                  [views] =&gt; 2639
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; assignments
                  [views] =&gt; 21611
              )
  
          [2] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; collaborations
                  [views] =&gt; 6
              )
  
          [3] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; conferences
                  [views] =&gt; 6
              )
  
          [4] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; discussions
                  [views] =&gt; 29962
              )
  
          [5] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; files
                  [views] =&gt; 13649
              )
  
          [6] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; general
                  [views] =&gt; 23497
              )
  
          [7] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; grades
                  [views] =&gt; 5473
              )
  
          [8] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; groups
                  [views] =&gt; 231
              )
  
          [9] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; modules
                  [views] =&gt; 27258
              )
  
          [10] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; other
                  [views] =&gt; 18186
              )
  
          [11] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; pages
                  [views] =&gt; 16576
              )
  
          [12] =&gt; Array
              (
                  [id] =&gt; 
                  [category] =&gt; quizzes
                  [views] =&gt; 6206
              )
  
      )
  
  )
  </code></pre>