You are here: Sorting an object array by an object property - how do you do it? « PHP Programming Language « IT news, forums, messages
Sorting an object array by an object property - how do you do it?

Posted by comp.lang.php on 09/11/06 14:40

[PHP]
array_walk($result, create_function('$a, $b', 'return
(strtolower($a->{$section . "_name"}) < strtolower($b->{$section .
"_name"}));'), $section);
[/PHP]

I thought this would sort an object array by the property {$section .
"_name"} (the variable $section has multiple values, hence, the object
array might be "image_name", "video_name", "audio_name",
"anything_name", but it will definitely exist, by whatever name
comprises ${section}_name, in the object property within the object
that makes up each array element), however, the sorting never takes
place.

How can I ensure that the object array is always sorted by
$obj->{$section . "_name"}?

Thanx
Phil

 

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

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