usort inside a class

This is a discussion on usort inside a class within the PHP General forums, part of the PHP Programming Forums category; Hi, i'm trying to build a class that sorts a multidimensional array. I'm using the php function "...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-09-2008
It Maq
 
Posts: n/a
Default usort inside a class

Hi,

i'm trying to build a class that sorts a multidimensional array.
I'm using the php function "usort".

I declared the comparision function as a method of my class but i'm unable to give it as argument to the function usort.

this "usort($this->arr, $this->cmpi)" gaves the following error: usort() [function.usort]: Invalid comparison function

i tried to do "usort($this->arr, 'cmpi')" but it does not work either.

Thanks


__________________________________________________ __________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ

Reply With Quote
  #2 (permalink)  
Old 05-09-2008
Richard Heyes
 
Posts: n/a
Default Re: [PHP] usort inside a class

> i'm trying to build a class that sorts a multidimensional array.
> I'm using the php function "usort".
>
> I declared the comparision function as a method of my class but i'm unable to give it as argument to the function usort.
>
> this "usort($this->arr, $this->cmpi)" gaves the following error: usort() [function.usort]: Invalid comparison function
>
> i tried to do "usort($this->arr, 'cmpi')" but it does not work either.


If it's anything like other functions, try this:

usort($this->arr, array($this, 'cmpi'));

--
Richard Heyes

+----------------------------------------+
| Access SSH with a Windows mapped drive |
| http://www.phpguru.org/sftpdrive |
+----------------------------------------+
Reply With Quote
  #3 (permalink)  
Old 05-09-2008
It flance
 
Posts: n/a
Default Re: [PHP] usort inside a class

It works thanks a lot!


--- On Fri, 5/9/08, Richard Heyes <richardh@phpguru.org> wrote:

> From: Richard Heyes <richardh@phpguru.org>
> Subject: Re: [php] usort inside a class
> To: itmaqurfe@yahoo.com
> Cc: php-general@lists.php.net
> Date: Friday, May 9, 2008, 8:47 PM
> > i'm trying to build a class that sorts a

> multidimensional array.
> > I'm using the php function "usort".
> >
> > I declared the comparision function as a method of my

> class but i'm unable to give it as argument to the
> function usort.
> >
> > this "usort($this->arr, $this->cmpi)"

> gaves the following error: usort() [function.usort]:
> Invalid comparison function
> >
> > i tried to do "usort($this->arr,

> 'cmpi')" but it does not work either.
>
> If it's anything like other functions, try this:
>
> usort($this->arr, array($this, 'cmpi'));
>
> --
> Richard Heyes
>
> +----------------------------------------+
> | Access SSH with a Windows mapped drive |
> | http://www.phpguru.org/sftpdrive |
> +----------------------------------------+



__________________________________________________ __________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:09 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0