note 23528 added to function.array-multisort

From: Date: Sun, 21 Jul 2002 04:32:00 +0000
Subject: note 23528 added to function.array-multisort
Groups: php.notes 
Request: Send a blank email to php-notes+get-33352@lists.php.net to get a copy of this message
The original post is correct... not the second post on this code: The code from If you have an array that contains output from a SQL SELECT statment and you want to sort the array on a column, you have to create a separate array containing the values of that column like so: //Get table output into $rows array $result = mysql_query("SELECT field1, field2 from table"); while ($rows[] = mysql_fetch_array($result)) {} //Sort on field2 foreach ($rows as $val) { $sortarray[] = $val['field2']; } array_multisort($rows, $sortarray); //Now, $rows is sorted on field2 If anyone knows an easier way to do this, please let us know! -- http://www.php.net/manual/en/function.array-multisort.php http://master.php.net/manage/user-notes.php?action=edit+23528 http://master.php.net/manage/user-notes.php?action=delete+23528 http://master.php.net/manage/user-notes.php?action=reject+23528

« previous php.notes (#33352) next »