title: imap_sort limit the number of results?
body: <p>I am using PHP with IMAP. I need to retrieve the 20 most new emails from a folder. I user imap_sort to sort by date, but the problem is that for a large folder with 700 and more emails it takes ages.</p>
  
  <p>Is there a way i can use PHP IMAP to sort messages by date and bring only the latest 20 emails?</p>
  
  <p>Maybe to use imap_search ?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>$start_from  = params::cleanDefault($_GET, 'start_from', 0);
  $limit       = params::cleanDefault($_GET, 'limit', 20);
  $sort_by     = params::cleanDefault($_GET, 'sort_by', 'SORTARRIVAL');
  
  $emails = imap_sort($mbox, $sort_by, 1, SE_NOPREFETCH);
  $emails = array_slice($emails, $start_from, $limit); 
  </code></pre>
  
  <p>Thanks.</p>