note 54957 added to function.usort

From: Date: Wed, 20 Jul 2005 20:56:25 +0000
Subject: note 54957 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-92228@lists.php.net to get a copy of this message
When I query a DB I usually put my record set inside of a multi-dimentional array. I finally wrote a program that will allow you to sort your record set by column after you put it in an array. <?php $test = array(); $test[0]['name'] = 'jeremy'; $test[0]['email'] = 'lala@fishies.com'; $test[0]['phone'] = '123-123-1234'; $test[0]['trick'] = 'mezopia'; $test[1]['name'] = 'Amanda'; $test[1]['email'] = 'hot@hotmail.com'; $test[1]['phone'] = '123-123-1235'; $test[1]['trick'] = 'youarecool'; $test[2]['name'] = 'john'; $test[2]['email'] = 'wowee@yahoo.com'; $test[2]['phone'] = '123-123-3333'; $test[2]['trick'] = 'goneinanhour'; print_r(columnSort($test, 'name')); function columnSort($unsorted, $column) { $sorted = $unsorted; for ($i=0; $i < sizeof($sorted)-1; $i++) { for ($j=0; $j<sizeof($sorted)-1-$i; $j++) if ($sorted[$j][$column] > $sorted[$j+1][$column]) { $tmp = $sorted[$j]; $sorted[$j] = $sorted[$j+1]; $sorted[$j+1] = $tmp; } } return $sorted; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.usort.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54957 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54957&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54957&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54957&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54957&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54957&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54957&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54957&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92228) next »