title: How to find a number which is less than and closest to number X in an array?
body: <p>For example I have array:</p>
  
  <pre><code>Array(
    [0] =&gt; 15
    [1] =&gt; 6
    [2] =&gt; 19
    [3] =&gt; 21
    [4] =&gt; 18
  )
  </code></pre>
  
  <p>If current time is 20 then I need value 19 (which is less than and near to 20)</p>
  
  <p>similarly if I pass my X number as 17 it will return 15 from array.</p>
  
  <p>If 7 then it should return 6.</p>
  
  <p>Please suggest how to achieve that with PHP?</p>
  
  <p>Thanks!</p>