Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

![]() |
![]() |
![]() |

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