title: Search nested multidimensional array
body: <p>I have a function that fills an array:</p>
  
  <pre><code>foreach ($request-&gt;get('ids') as $id) {
      $pdfArray['other']++; // Yes this is initialized
      $pdfArray['rows'][$i]['id'] = $schedule-&gt;getId();
      $pdfArray['rows'][$i]['date'] = $schedule-&gt;getStart()-&gt;format('d.m.Y');
      $pdfArray['rows'][$i]['dateSort'] = $schedule-&gt;getStart()-&gt;format('Y-m-d H:i');
      $pdfArray['rows'][$i]['from'] = $schedule-&gt;getStart()-&gt;format('H:i');
      $pdfArray['rows'][$i]['to'] = $schedule-&gt;getEnd()-&gt;format('H:i');
      $pdfArray['rows'][$i]['desc'] = $schedule-&gt;getDescription();
  }
  </code></pre>
  
  <p><strong>What I want to do</strong></p>
  
  <p>On each loop, I want to check if the array (so far) already has a <code>desc</code> entry equal to the current <code>$schedule-&gt;getDescription()</code> AND the same <code>date</code> as <code>$schedule-&gt;getStart()-&gt;format('d.m.Y')</code> (actually more, but let's keep it simple)</p>
  
  <p><strong>What I tried</strong> </p>
  
  <pre><code>public function recursive_array_search($needle,$haystack) {
      foreach($haystack as $key=&gt;$value) {
          $current_key=$key;
          if($needle===$value OR (is_array($value) &amp;&amp; $this-&gt;recursive_array_search($needle,$value) !== false)) {
              return $current_key;
          }
      }
      return false;
  }
  </code></pre>
  
  <p><a href="http://php.net/manual/de/function.array-search.php#91365" rel="nofollow">Source</a></p>
  
  <p>I use it like that:</p>
  
  <pre><code>if ($this-&gt;recursive_array_search($schedule-&gt;getDescription(), $pdfArray['rows']) &amp;&amp;
      $this-&gt;recursive_array_search($schedule-&gt;getStart()-&gt;format('d.m.Y'), $pdfArray['rows'])){
         $pdfArray['ma'][$schedule-&gt;getId()]++;
  }
  </code></pre>
  
  <p>but this is <code>true</code> when ANY of the <code>start</code> or <code>desc</code> are SOMEWHERE in the current array.</p>
  
  <p>How would I check if <code>desc</code> is found and <code>start</code> is in the SAME <code>$i</code> level?</p>
  
  <p><strong>EDIT for example</strong></p>
  
  <p>Let's say I have 10 <code>$id</code>s to loop through. After 2 loops, the <code>$pdfArray</code> looks like this:</p>
  
  <pre><code>Array
  (
  [other] =&gt; 2
  [rows] =&gt; Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 1
                  [date] =&gt; 13.07.2016
                  [dateSort] =&gt; 2016-07-13 08:00
                  [from] =&gt; 08:00
                  [to] =&gt; 09:00
                  [desc] =&gt; TEST
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 2
                  [date] =&gt; 12.07.2016
                  [dateSort] =&gt; 2016-07-12 08:00
                  [from] =&gt; 08:00
                  [to] =&gt; 09:00
                  [desc] =&gt; TEST
              )
  
      )
  </code></pre>
  
  <p>)</p>
  
  <p>The next iteration has the following:</p>
  
  <p><code>$schedule-&gt;getStart()-&gt;format('d.m.Y')</code> => <code>12.07.2016</code></p>
  
  <p><code>$schedule-&gt;getDescription()</code> => <code>TEST</code></p>
  
  <p>So I want to have the info that the combination already exists in the array.</p>
  
  <p>BUT</p>
  
  <p><code>$schedule-&gt;getStart()-&gt;format('d.m.Y')</code> => <code>12.07.2016</code></p>
  
  <p><code>$schedule-&gt;getDescription()</code> => <code>TEST2</code></p>
  
  <p>should NOT return true upon checking of it exists.</p>