You are here: Re: sorting an associative array of objects by value? « PHP Programming Language « IT news, forums, messages
Re: sorting an associative array of objects by value?

Posted by Michael Fesser on 12/13/06 00:38

..oO(Greg D)

>I'm trying to sort an array of objects within an object. Included is a
>dumbed down example so that we can get at the meat of the issue without
>worrying about complexity or validation. Basically, Funk is an object that
>has a name (string) and a value(int). FunkThis represents an object
>containing a list of Funks, with each key corresponding to the name of the
>Funk. I want to sort this list by val, but I get a Warning: usort():
>Invalid comparison function error when I run the script. Keep in mind that
>this is for PHP 4
>[...]

callback
http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback

| A method of an instantiated object is passed as an array containing an
| object as the element with index 0 and a method name as the element
| with index 1.

Since compareFunks() is a method of FunkThis, you need

uasort($list, array($this, 'compareFunks'));

to call it.

Micha

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация