Re: usort comparison function
| From: | Jon Parise | Date: | Sun, 30 Jul 2000 02:34:06 +0000 |
| Subject: | Re: usort comparison function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9014@lists.php.net to get a copy of this message | ||
On Sat, Jul 29, 2000 at 07:26:28PM -0700, Matthew Kendall wrote:
> The usort function allows an array to be sorted on the basis of a
> user-supplied function that compares two elements, like
> usort($arr,cmp).
>
> A reader-annotation in the manual points out that the user function
> cmp() cannot be a member of a class and this seems to be consistent
> with my experiments, but it is somewhat ugly. Does anyone know if
> there is a workaround for this? Is it possible to use a comparison
> function that is anything other than a global function?
> Specifically, I want to use this->cmp().
If you're using a recent version of PHP 4, you can use:
usort($my_array, array($this, "cmp_function"));
--
Jon Parise (jon@csh.rit.edu) . Rochester Inst. of Technology
http://www.csh.rit.edu/~jon/ : Computer Science House
Member