note 8587 modified in function.usort by felipe

From: Date: Mon, 21 Jul 2008 01:46:03 +0000
Subject: note 8587 modified in function.usort by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142387@lists.php.net to get a copy of this message
Needed a date sort and I didn't know if one was available so I wrote one. Maybe it'll help someone: <?php function DateSort($a,$b,$d="-") { if ($a == $b) { return 0; } else { //Convert into dates and compare list($am,$ad,$ay)=split($d,$a); list($bm,$bd,$by)=split($d,$b); if (mktime(0,0,0,$am,$ad,$ay) < mktime(0,0,0,$bm,$bd,$by)) { return -1; } else { return 1; } } } ?> $d is the delimeter --was-- Needed a date sort and I didn't know if one was available so I wrote one. Maybe it'll help someone: <?php function DateSort($a,$b,$d="-") { if ($a == $b) { return 0; } else { //Convert into dates and compare list($am,$ad,$ay)=split($d,$a); list($bm,$bd,$by)=split($d,$b); if (mktime(0,0,0,$am,$ad,$ay) < mktime(0,0,0,$bm,$bd,$by)) { return -1; } else { return 1; } } } ?> $d is the delimeter http://php.net/manual/en/function.usort.php

« previous php.notes (#142387) next »