title: How to get just smaller value than target from an array
body: <p>I am trying to refund funds to the customer whenever one cancel the booking. As I have different refund percent according to the cancellation time, considering how early someone cancel the booking. </p>
  
  <p>Currently, there are mainly two array of data:</p>
  
  <p>1) TimeMeta : This is an array of reserved time slot.</p>
  
  <pre><code>$time_meta = array([
      [
          'id' =&gt; '9',
          'start_date' =&gt; '2019-06-19',
          'end_date' =&gt; '2019-06-19',
          'start_time' =&gt; '08:00:00',
          'end_time' =&gt; '09:00:00'
      ],
      [
          'id' =&gt; '10',
          'start_date' =&gt; '2019-06-20',
          'end_date' =&gt; '2019-06-20',
          'start_time' =&gt; '08:00:00',
          'end_time' =&gt; '09:00:00'
      ],
      [
          'id' =&gt; '11',
          'start_date' =&gt; '2019-06-21',
          'end_date' =&gt; '2019-06-20',
          'start_time' =&gt; '08:00:00',
          'end_time' =&gt; '09:00:00'
      ],
      [
          'id' =&gt; '12',
          'start_date' =&gt; '2019-06-22',
          'end_date' =&gt; '2019-06-20',
          'start_time' =&gt; '08:00:00',
          'end_time' =&gt; '09:00:00'
      ],
      [
          'id' =&gt; '13',
          'start_date' =&gt; '2019-06-23',
          'end_date' =&gt; '2019-06-23',
          'start_time' =&gt; '08:00:00',
          'end_time' =&gt; '09:00:00'
      ]
  ])
  </code></pre>
  
  <p>2) Refunds value according to hours</p>
  
  <pre><code>$refunds = array([
      [
          'before_hours' =&gt; '12',
          'refund_percent' =&gt; '50'
      ],
      [
          'before_hours' =&gt; '24',
          'refund_percent' =&gt; '70'
      ],
      [
          'before_hours' =&gt; '48',
          'refund_percent' =&gt; '90'
      ]
  ])
  </code></pre>
  
  <p>Upto this point I could calculate the difference between current datetime and the reserved datetime as follows</p>
  
  <pre><code>foreach($time_meta as $ik =&gt; $iv){
                  $start_datetime = $iv-&gt;start_date-&gt;format('Y-m-d').' '.$iv-&gt;start_time;
                  $start_datetime = \Carbon\Carbon::parse($start_datetime);
                  $diff = $now-&gt;diffInHours($start_datetime,false);
  
  // NEED CODE HERE TO DETERMINE THE EXACT REFUND PERCENT
  // ACCORDING TO TIME DIFFERENCE BETWEEN NOW AND THE BOOKED DATE
  
  }
  </code></pre>
  
  <p>Now, I want to find that best matched refund percent. So, for example if user tries to cancel the booking event before 23 hours, the refund percent should be only 50 percentage, as 12 hour is just smaller than 23 hours from <code>refund</code> array.</p>
  
  <p>Test Case</p>
  
  <pre><code>  11 hrs before = (should not be refund) as lowest value is 12 hours before
    23 hrs before = (should be refund as) 12 hours before
    24 hrs before = (should be refund as) 24 hours before
    46 hrs before = (should be refund as) 24 hours before
    48 hrs before = (should be refund as) 48 hours before
  
  </code></pre>
  
  <p>Also, if the  event date is already passed, in that case <code>$diff</code> value would be negative, this means there should be no refund for passed date.</p>