note 53588 added to function.sort

From: Date: Mon, 06 Jun 2005 21:02:04 +0000
Subject: note 53588 added to function.sort
Groups: php.notes 
Request: Send a blank email to php-notes+get-90024@lists.php.net to get a copy of this message
I had always problems sorting a array with many items. The given php-functions couldn't sort the array correctly, so I decided to write an own function: This function sorts over 100 items correctly (also if there are values with special signs): <?php //Array-Sort for an Array with textvalues function array_sort($array) { foreach($array as $wert) { $bereich=strtolower(substr($wert,0,1)); $add[$bereich][strtolower($wert)]=$wert; } $key=array_keys($add); sort($key,SORT_STRING); for($x=0;$x<count($key);$x++) { $akt=$add[$key[$x]]; ksort($akt,SORT_REGULAR); foreach($akt as $wert) { $out[]=$wert; } } return $out; } ?> MFG Jens Contact: http://weltie.com ---- Manual Page -- http://www.php.net/manual/en/function.sort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+53588 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+53588&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+53588&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+53588&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+53588&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+53588&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+53588&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#90024) next »