title: php array_filter by date
body: <p>New to PHP so not sure if this is the best way. Basically I have a record-set with results, now I could do 3 or 4 queries &amp; return the results as I need them, but I thought it would be more efficient to have one query and filter the results in an array as I need them.</p>
  
  <p>I get the results into an array, now I want to display the results by day week and month so it makes sense to me to loop the array 3 times for day, week and month rather than 3 calls to the database.</p>
  
  <p>First question is this the best way in PHP???</p>
  
  <p>Second is I cant work out how to use the array_filter($array_name, DATE?) I can't get the date part working.</p>
  
  <p>The array/recordset could be:</p>
  
  <p>name, target, date</p>
  
  <p>and I want to show the results of this by day, week &amp; month.</p>
  
  <p>So I got:</p>
  
  <pre><code>    array_filter($staff_tagret_results,"evaldate");
  </code></pre>
  
  <p>And a function:</p>
  
  <pre><code>    function evaldate($x) {
      if($staff_tagret_results == DAY/WEEK/MONTH){
          return true;
      }
  }
  </code></pre>
  
  <p>But I can't find out how to target the date filed of the array and compare against today?</p>
  
  <p>Thanks for any advice.</p>
  
  <p>ARRAY CONTENTS:</p>
  
  <pre><code>Array(
      [0] =&gt; Array(
          [staff_id] =&gt; 11[0] =&gt; 11[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 115[2] =&gt; 115
      ) [1] =&gt; Array(
          [staff_id] =&gt; 4[0] =&gt; 4[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 115[2] =&gt; 115
      ) [2] =&gt; Array(
          [staff_id] =&gt; 9[0] =&gt; 9[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 115[2] =&gt; 115
      ) [3] =&gt; Array(
          [staff_id] =&gt; 11[0] =&gt; 11[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 115[2] =&gt; 115
      ) [4] =&gt; Array(
          [staff_id] =&gt; 4[0] =&gt; 4[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 115[2] =&gt; 115
      ) [5] =&gt; Array(
          [staff_id] =&gt; 9[0] =&gt; 9[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 115[2] =&gt; 115
      ) [6] =&gt; Array(
          [staff_id] =&gt; 11[0] =&gt; 11[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 240[2] =&gt; 240
      ) [7] =&gt; Array(
          [staff_id] =&gt; 4[0] =&gt; 4[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 240[2] =&gt; 240
      ) [8] =&gt; Array(
          [staff_id] =&gt; 9[0] =&gt; 9[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 240[2] =&gt; 240
      ) [9] =&gt; Array(
          [staff_id] =&gt; 4[0] =&gt; 4[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 180[2] =&gt; 180
      ) [10] =&gt; Array(
          [staff_id] =&gt; 9[0] =&gt; 9[work_date] =&gt; 2014 - 02 - 12[1] =&gt; 2014 - 02 - 12[target_set] =&gt; 180[2] =&gt; 180
      )
  )
  </code></pre>