note 47294 deleted from function.array-multisort by aidan

From: Date: Sun, 14 Nov 2004 17:34:55 +0000
Subject: note 47294 deleted from function.array-multisort by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-80519@lists.php.net to get a copy of this message
Note Submitter: jagallegos at gmail dot com ---- Hi! This is my source code to sort datatables <?php $table[0]["index"] = 1; $table[0]["name"] = "d"; $table[1]["index"] = 4; $table[1]["name"] = "a"; $table[2]["index"] = 3; $table[2]["name"] = "b"; $table[3]["index"] = 2; $table[3]["name"] = "c"; $table_sorted = sort_table($table,"name",0); print_r($table); print "\n\n"; print_r($table_sorted); /* * SORTING DATATABLES BY A SPECIFIED FIELD OR COLUMN IN ASC-DESC MODE * MODE = 0 (ASC) 1 (DESC) */ function sort_table($datatable,$field,$mode) { $i_cnt = count($datatable); for($i=0;$i<$i_cnt;$i++) { foreach($datatable[$i] as $key => $value) { $array[$key][$i] = $value; } } $mode == 0 ? asort($array[$field]) : arsort($array[$field]); $_keys = array_keys($array[$field]); for($i=0;$i<$i_cnt;$i++) { foreach($array as $key => $value) { $_hash[$i][$key] = $array[$key][$_keys[$i]]; } } return $_hash; } ?>

« previous php.notes (#80519) next »