Tip Details Add a Related Tip

Rate as: Positive Negative

Referencing methods in PHP usort

The usort function in PHP allows you to sort data based on the results of a function that you define. But if you are using OO PHP and you want to avoid functions, it turns out you can use methods of objects too with a slight variation to the usort call. The usual call to usort looks something like this:

usort($arrayToBeSorted, 'theNameOfAFunction');

If you want to use a method in an object to act as the sorting function, you can do so by making the call like this:

usort($arrayToBeSorted, array('theNameOfAnObject', 'theNameOfAMethod'));

You can also use this type of calling if the sorting method exists in the object that you are calling it from within. To do this, use this format:

usort($arrayToBeSorted, array($this, 'theNameOfAMethod'));

Happy sorting!
Rating: no ratings, 0 total Votes
Categories: php coding programming
Added: on Jun 13, 2008 at 11:18 am
Added By: an anonymous user

Comments on this Tip

Add a Comment
There are no comments for this tip
Your Comment:
(how to format)
Rate This Tip:

Verify Humanity:
Sorry, we know it's annoying, but please enter the characters shown in the image to the left so that we know you're an actual person and not an evil spammer. Thanks.
       

Related Tips

How to Find a Random Date in PHP

25% positive, 0 comments
– Tip added by Walkere on Feb 07, 2008 at 8:25 pm

Best PHP reference

Categories: PHP coding programming
100% positive, 0 comments
– Tip added by rlansky on Mar 07, 2007 at 2:38 pm

How to Syndicate an RSS Feed On Your Site

100% positive, 0 comments
– Tip added by Walkere on Feb 09, 2008 at 5:48 pm

How to Create a Random Password in PHP

100% positive, 0 comments
– Tip added by Walkere on Feb 03, 2008 at 9:14 am

Single versus double quotes in PHP

Categories: PHP coding programming
no ratings, 0 comments
– Tip added by Marcos84 on Mar 31, 2007 at 8:00 pm

A better way to paginate through results

100% positive, 2 comments - last added on Mar 09, 2007 at 7:27 am
– Tip added by tipstr on Mar 08, 2007 at 12:33 pm

Using functions in conditionals in Smarty

Categories: php programming Smarty web
100% positive, 3 comments - last added on May 21, 2008 at 1:36 pm
– Tip added by rlansky on Aug 10, 2007 at 1:02 pm

Something to consider before switching platforms

100% positive, 0 comments
– Tip added by an anonymous user on Sep 25, 2007 at 7:31 pm

Detecting if a variable exists in Javascript

100% positive, 1 comment - last added on Sep 03, 2008 at 6:12 am
– Tip added by an anonymous user on Jul 22, 2008 at 8:31 am

Redirecting in PHP

100% positive, 0 comments
– Tip added by an anonymous user on Jul 17, 2008 at 7:27 am

compressing javascript

100% positive, 0 comments
– Tip added by an anonymous user on Jun 12, 2008 at 3:02 pm

Copyright date on sites

Categories: web programming php Smarty
100% positive, 0 comments
– Tip added by an anonymous user on Mar 11, 2008 at 8:14 am

How to Send E-Mail in PHP: A “Share This” Form

33% positive, 0 comments
– Tip added by Walkere on Feb 06, 2008 at 6:45 pm

Quick UML reference

Categories: coding programming UML
100% positive, 0 comments
– Tip added by an anonymous user on Dec 24, 2007 at 8:52 am

Answering a tricky interview question on swapping

100% positive, 1 comment - last added on Aug 20, 2007 at 8:55 am
– Tip added by an anonymous user on Aug 20, 2007 at 7:26 am

Best CVS book out there is available on-line... for free

Categories: CVS coding programming free
100% positive, 0 comments
– Tip added by Marcos84 on Mar 09, 2007 at 9:20 am

553 sorry, your envelope sender domain must exist errors

no ratings, 0 comments
– Tip added by an anonymous user on Sep 26, 2008 at 3:35 pm

CakePHP: Working with Associations

no ratings, 0 comments
– Tip added by an anonymous user on May 08, 2008 at 4:09 am

Javascript: How to Create a Random Number

0% positive, 0 comments
– Tip added by Walkere on Feb 23, 2008 at 9:49 pm

File upload progress meters in PHP

Categories: programming web 2.0 php
no ratings, 0 comments
– Tip added by an anonymous user on Jun 16, 2007 at 5:03 pm