title: Search Array : array_filter vs loop
body: <p>I am really new in PHP and need a suggestion about array search.</p>
  
  <p>If I want to search for an element inside a multidimensional array, I can either use <code>array_filter</code> or I can loop through the array and see if an element matching my criteria is present.</p>
  
  <p>I see both suggestion at many places. Which is faster? Below is a sample array.</p>
  
  <pre><code>Array ( 
    [0] =&gt; Array ( 
      [id] =&gt; 4e288306a74848.46724799
      [question] =&gt; Which city is capital of New York?
      [answers] =&gt; Array ( 
        [0] =&gt; Array ( 
          [id] =&gt; 4e288b637072c6.27436568 
          [answer] =&gt; New York 
          [question_id_fk] =&gt; 4e288306a74848.46724799 
          [correct] =&gt; 0 
        ) 
        [1] =&gt; Array ( 
          [id] =&gt; 4e288b63709a24.35955656 
          [answer] =&gt; Albany 
          [question_id_fk] =&gt; 4e288306a74848.46724799 
          [correct] =&gt; 1 
        ) 
      )
    )
  )
  </code></pre>
  
  <p>I am searching like this.</p>
  
  <pre><code>$thisQuestion = array_filter($pollQuestions, function($q) {
    return questionId == $q["id"];
  });
  </code></pre>