note 69621 added to function.uksort
| From: | joelith at cyberone dot com dot au | Date: | Wed, 13 Sep 2006 05:13:48 +0000 |
| Subject: | note 69621 added to function.uksort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117088@lists.php.net to get a copy of this message | ||
You can use this function to sort an array of days into order. We grabbed some data from a database
which comes out as array('Monday'=>34, 'Sunday'=>45... etc but the day is
not in order. So use this:
<?php
function cmp($a, $b){
$days = array('Tuesday'=>0, 'Wednesday'=>1, 'Thursday'=>2,
'Friday'=>3, 'Saturday'=>4, 'Sunday'=>5,
'Monday'=>6);
// company logic dictates a week begins on a Tuesday.
if ($days[$a]<$days[$b]){
return -1;
}else{
return 1;
}
}
?>
----
Server IP: 203.16.234.20
Probable Submitter: 165.228.126.119
----
Manual Page -- http://www.php.net/manual/en/function.uksort.php
Edit -- https://master.php.net/note/edit/69621
Del: integrated -- https://master.php.net/note/delete/69621/integrated
Del: useless -- https://master.php.net/note/delete/69621/useless
Del: bad code -- https://master.php.net/note/delete/69621/bad+code
Del: spam -- https://master.php.net/note/delete/69621/spam
Del: non-english -- https://master.php.net/note/delete/69621/non-english
Del: in docs -- https://master.php.net/note/delete/69621/in+docs
Del: other reasons-- https://master.php.net/note/delete/69621
Reject -- https://master.php.net/note/reject/69621
Search -- https://master.php.net/manage/user-notes.php