On 22/03/07, Sean Coates <[EMAIL PROTECTED]> wrote:
> function sort_by_key($key) {

For the record, I do like this syntax, but it COULD be rewritten using
current practices (see below).

I know, and it can be done without typing so much:

class SortByKey {
   function __call($name, $a) {
       if ($a[0][$name] < $a[1][$name])
           return -1;
       if ($a[0][$name] == $a[1][$name])
           return 0;
       return 1;
   }
}
$a = array(
   array("a" => 1, "b" => 2),
   array("a" => 2, "b" => 1),
);
usort($a, array(new SortByKey, "b"));

That doesn't change the fact that it's a hack ;)

Regards,
Stefan

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to