RE: [PHP] usort within a class
| From: | Peter Lauri | Date: | Wed, 23 Aug 2006 22:41:26 +0000 |
| Subject: | RE: [PHP] usort within a class | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-241067@lists.php.net to get a copy of this message | ||
Working perfect, thanks :) I did RTFM but I did miss that :)
-----Original Message-----
From: Robert Cummings [mailto:robert@interjinn.com]
Sent: Thursday, August 24, 2006 3:46 AM
To: Peter Lauri
Cc: php-general@lists.php.net
Subject: Re: [PHP] usort within a class
On Thu, 2006-08-24 at 03:13 +0700, Peter Lauri wrote:
> Hi,
>
> Is it possible to have the compare function in a class? I can not get it
to
> work, this is pseudo code:
>
> class A {
> function getArray() {
> //dosomethingandgetanarray
> $array = blabla;
> usort($array, "$this->myCompareFunction");
> //Or maybe "A::myCompareFunction"
> }
>
> function myCompareFunction($a, $b) {
> //return rajraj depending on $a and $b values
> }
> }
>
>
> Right now I have keep the compare function outside of the class like this:
>
> class A {
> function getArray() {
> //dosomethingandgetanarray
> $array = blabla;
> usort($array, "$this->myCompareFunction");
> }
> }
>
> function myCompareFunction($a, $b) {
> //return rajraj depending on $a and $b values
> }
>
RTF :)
usort( $array, array( $this, 'myCompareFunction' ) )
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'