title: Remove array elements that are less than X
body: <p>I have arrays:</p>
  
  <pre><code>$arr1 = array(5, 3, 9, 11, 6, 15);
  $arr2 = array(11, 20, 1, 3, 8);
  </code></pre>
  
  <p>Now I need to loop through <code>$arr1</code> and find the largest number that is less than <code>X</code>:</p>
  
  <pre><code>foreach($arr1 as $x) {
     //need element that is MAX in $arr2 but is less than $x
  }
  </code></pre>
  
  <p>so for example for the first run when <code>$x = 5</code>, maximum in <code>$arr2</code> is <strong>3</strong> that is less than <strong>5</strong>.</p>
  
  <p>Is it possible to do this without having nested loop? I do not want to loop through <code>$arr2</code>. I tried using <code>array_filter</code> but didnt really work. Maybe I used it wrong.</p>
  
  <p>This is what I tried with <code>array_filter</code>:</p>
  
  <pre><code>$results = array();
  foreach($arr1 as $x) {
     $max = max(array_filter($arr2, function ($x) { return $x &lt; $y; }));
  
     $results[$x] = $max;
  }
  </code></pre>
  
  <p>The result should be this:</p>
  
  <pre><code>5  =&gt; 3, 
  3  =&gt; 1, 
  9  =&gt; 8, 
  11 =&gt; 8, 
  6  =&gt; 3, 
  15 =&gt; 11
  </code></pre>