Re: PATCH: anonymous functions in PHP
| From: | Stefan Walk | Date: | Thu, 22 Mar 2007 15:25:32 +0000 |
| Subject: | Re: PATCH: anonymous functions in PHP | ||
| References: | 1 2 3 4 5 6 7 8 9 10 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-28554@lists.php.net to get a copy of this message | ||
On 22/03/07, Sean Coates <sean@caedmon.net> 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