PhpDig.net

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




imap_sort

Name

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

Synopsis

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

Returns

An array of messages; FALSE on error

Description

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.

Version

From versions 3.0.3 and 4.0

Example

Example 620. Sort messages by subject

<?php
$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";

}

imap_close($imap);
?>

Output
Unsorted:
First message
Second message
A message

Sorted:
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 http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ 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.