note 74816 added to function.usort

From: Date: Sat, 28 Apr 2007 11:09:48 +0000
Subject: note 74816 added to function.usort
Groups: php.notes 
Request: Send a blank email to php-notes+get-125951@lists.php.net to get a copy of this message
<?php // class __partial { var $args; var $fn; function __partial($args) { $this->fn = array_shift ($args); $this->args = $args; } function right() { $args = func_get_args (); array_splice ($args, count($args), 0, $this->args); return call_user_func_array ($this->fn, $args); } function left() { $args = func_get_args (); array_splice ($args, 0, 0, $this->args); return call_user_func_array ($this->fn, $args); } } function rcurry () { $closure = &new __partial (func_get_args ()); return array ($closure, 'right'); } function lcurry () { $closure = &new __partial (func_get_args ()); return array ($closure, 'left'); } function compare($a, $b, $key) { if ($a[$key] == $b[$key]) { return 0; } return ($a[$key] > $b[$key]) ? +1 : -1; } function sortOn ($array, $key) { usort ($array, rcurry('compare', $key)); return $array; } $array = array (array ('key' => 1), array ('key' => 5), array ('key' => 3)); print_r (sortOn ($array, 'key')); ?> ---- Server IP: 195.54.192.44 Probable Submitter: 193.233.48.169 (proxied: unknown, unknown, 193.233.53.129) ---- Manual Page -- http://www.php.net/manual/en/function.usort.php Edit -- https://master.php.net/note/edit/74816 Del: integrated -- https://master.php.net/note/delete/74816/integrated Del: useless -- https://master.php.net/note/delete/74816/useless Del: bad code -- https://master.php.net/note/delete/74816/bad+code Del: spam -- https://master.php.net/note/delete/74816/spam Del: non-english -- https://master.php.net/note/delete/74816/non-english Del: in docs -- https://master.php.net/note/delete/74816/in+docs Del: other reasons-- https://master.php.net/note/delete/74816 Reject -- https://master.php.net/note/reject/74816 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125951) next »