Computing.Net > Forums > Web Development > usort Function Within a Class

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

usort Function Within a Class

Reply to Message Icon

Name: Michael J (by mjdamato)
Date: August 10, 2005 at 14:27:21 Pacific
OS: XP
CPU/Ram: 2.4P4/1GB
Comment:

I am attempting to sort an array within a class using the usort command, but am having difficulty in formating the function name parameter.

The usort command is normally used like this:

usort ($array, "compareFunction")

where the compare function is included within quotes as shown.

My problem is that I am trying to use this within a class. My compare function is called sortChannels. In a class I would call the function using $this->sortChannels. But, I cannot figure out how to call the class function within usort.

I have tried:
usort($array, this->sortChannels);
usort($array, "this->sortChannels");
usort($array, this->"sortChannels");
usort($array, sortChannels);
usort($array, "sortChannels");

I keep getting the error - Warning: usort(): Invalid comparison function. Any ideas onhow I should format the class function within usort?

Michael J



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: August 10, 2005 at 15:19:26 Pacific
Reply:

After re-reading the usort manual on php.net for the 3rd or 4th time and some more trial and error I found the solution.

usort($array, array("className", "sortChannels"));


Michael J


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: usort Function Within a Class

javascript within a form www.computing.net/answers/webdevel/javascript-within-a-form/1105.html

CSS within a table www.computing.net/answers/webdevel/css-within-a-table/1568.html

checkbox within datagrid (ASP.NET) www.computing.net/answers/webdevel/checkbox-within-datagrid-aspnet/828.html