RE: [PHP] Tricky sorting problem

From: Date: Wed, 30 Oct 2002 17:51:58 +0000
Subject: RE: [PHP] Tricky sorting problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-122074@lists.php.net to get a copy of this message
> I need to sort an array based on three numbers that are situated in the > middle of each array element. For example: > > $list[] is an array, and contains the following [unsorted] elements: > > Super-S862-030.jpg > Super-S1162-040.jpg > Super-S874-010.jpg > Super-S1174-020.jpg > > I want to sort $list based on those last three numbers, just before the > extension, so that the new sort order is: > > Super-S874-010.jpg > Super-S1174-020.jpg > Super-S862-030.jpg > Super-S1162-040.jpg Maybe something like this? foreach($list as $k => $v) { $p = explode('-',$v); $new_list[$p[2]] = $v; } ksort($new_list); reset($new_list); $new_list will have the XXX number as the key of the array element and the name of the file corresponding to the number as it's value. If that won't work, let us know. ---John Holmes...

« previous php.general (#122074) next »