note 90710 added to function.natcasesort

From: Date: Tue, 05 May 2009 17:03:29 +0000
Subject: note 90710 added to function.natcasesort
Groups: php.notes 
Request: Send a blank email to php-notes+get-154254@lists.php.net to get a copy of this message
I kept getting varied results using natcasesort and sort on mixed arrays -- per the descriptions. Sometimes simple is better: A little snippet of code: <?php if($responders->num_rows) { $i=0; while($row= $responders->fetch_assoc()) { $user=getUserName($row['responderID']); $r[$i]= array("sortname"=>strtolower($user),"userName"=>$user, "userID"=>$row['responderID'], "responderID"=>$row['idresponders']); $i++; } sort($r); print_r($r); } ?> I simply created a lower cased sort field at the front of the result set and then sort by it -- which provides the expected result and leaves the actual needed fields unchanged. For the curious: all user information is kept completed in another database (and table) from the content database due to security reasons. The getUser functions we have written allow us to pull only what is legally allowed without exposing anything else. This is why a left join or something wasn't used and we have to build a pseudo result array here from both databases. ---- Server IP: 208.69.120.35 Probable Submitter: 68.205.9.228 ---- Manual Page -- http://www.php.net/manual/en/function.natcasesort.php Edit -- https://master.php.net/note/edit/90710 Del: integrated -- https://master.php.net/note/delete/90710/integrated Del: useless -- https://master.php.net/note/delete/90710/useless Del: bad code -- https://master.php.net/note/delete/90710/bad+code Del: spam -- https://master.php.net/note/delete/90710/spam Del: non-english -- https://master.php.net/note/delete/90710/non-english Del: in docs -- https://master.php.net/note/delete/90710/in+docs Del: other reasons-- https://master.php.net/note/delete/90710 Reject -- https://master.php.net/note/reject/90710 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154254) next »