Tip Details

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: 75% positive, 4 total Votes
Categories: php coding programming
Added: on Jun 13, 2008 at 11:18 am
Added By: an anonymous user
Searches: php usort method coding function

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

20% 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

Setting the Return-Path header when using mail in PHP

no ratings, 0 comments
– Tip added by an anonymous user on Dec 28, 2009 at 2:29 pm

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

Detecting if a variable exists in Javascript

100% positive, 2 comments - last added on Oct 21, 2009 at 2:29 pm
– Tip added by an anonymous user on Jul 22, 2008 at 8:31 am

553 sorry, your envelope sender domain must exist errors

100% positive, 0 comments
– Tip added by an anonymous user on Sep 26, 2008 at 3:35 pm

Unable to click in text input boxes on Internet Explorer

100% positive, 2 comments - last added on Aug 07, 2009 at 4:57 pm
– Tip added by Marcos84 on Dec 09, 2008 at 10:49 am

Something to consider before switching platforms

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

Determining keywords for your pages

100% positive, 0 comments
– Tip added by an anonymous user on Nov 13, 2008 at 10:28 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

PHP strftime errors in Smarty

no ratings, 0 comments
– Tip added by an anonymous user on Nov 03, 2009 at 3:04 pm

Creating charts in PHP

no ratings, 0 comments
– Tip added by an anonymous user on Nov 28, 2008 at 10:37 am

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