What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.



imap_sort — Returns an array of messages sorted by the specified method.


array imap_sort(connection, sortcriteria, reversesort, options);
int connection: IMAP connection ID
int sortcriteria: A sorting criteria
int reversesort: Reverses the sorting order
int options: Flags allowing additional functionality


An array of messages; FALSE on error


Sorts messages in the current mailbox. reversesort is a simple 0 for normal or 1 for reverse sorting.

Possible values for sortcriteria are: SORTDATE, SORTARRIVAL, SORTFROM, SORTSUBJECT, SORTTO, SORTCC, SORTSIZE. Only one option can be used.

options can be SE_UID to return the message UID rather then the message ID nd SE_NOPREFETCH to not prefetch sorted messages.


From versions 3.0.3 and 4.0


Example 620. Sort messages by subject

$imap = imap_open("{localhost}INBOX","graeme","inferno");

// get number of messages in INBOX
$number = imap_num_msg($imap);

// display unsorted messages
echo "Unsorted<BR>\n";
for ($i=1; $i<=$number; $i++) {
   $header = imap_header($imap, $i);
   echo "Subject: ", $header->Subject, "<BR>\n";


// sort the messages by subject
$sorted = imap_sort($imap, SORTSUBJECT, 0);

// display again
echo "Sorted:<BR>\n";
for ($i=0; $i<count($sorted); $i++) {
   $header = imap_header($imap, $sorted[$i]);
   echo "Subject: ", $header->Subject, "<BR>\n";



First message
Second message
A message

A message
First message
Second message

PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at The authors of this book have elected not to choose any options under the OPL. This online book was obtained from and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.