yanisdon Posted November 1, 2007 Share Posted November 1, 2007 Hi there, I've got an array of objects. The print_r() looks like this: stdClass Object ( [type] => book [name] => Book page [module] => book [description] => A book is a collaborative writing effort: users can collaborate writing the pages of the book. [help] => [has_title] => 1 [title_label] => Title [has_body] => 1 [body_label] => Body [min_word_count] => 0 [custom] => 0 [modified] => 1 [locked] => 1 [orig_type] => book ) stdClass Object ( [type] => event [name] => Event [module] => basicevent [description] => An event is a planned event with a start and end date, and displays in the events calendar. [help] => [has_title] => 1 [title_label] => Title [has_body] => 1 [body_label] => Body [min_word_count] => 0 [custom] => 0 [modified] => 1 [locked] => 1 [orig_type] => event ) stdClass Object ( [type] => blog [name] => Blog entry [module] => blog [description] => A blog is a regularly updated journal or diary made up of individual posts. [help] => [has_title] => 1 [title_label] => Title [has_body] => 1 [body_label] => Body [min_word_count] => 0 [custom] => 0 [modified] => 1 [locked] => 1 [orig_type] => blog ) What I like to be doing here is basically to sort 'alphabetically' by [type]. I can't use sort() since it expects an array. Any ideas? Link to comment https://forums.phpfreaks.com/topic/75583-sorting-an-object-array/ Share on other sites More sharing options...
trq Posted November 1, 2007 Share Posted November 1, 2007 Why are you using stdClass instead of an array? Link to comment https://forums.phpfreaks.com/topic/75583-sorting-an-object-array/#findComment-382433 Share on other sites More sharing options...
yanisdon Posted November 1, 2007 Author Share Posted November 1, 2007 Because I am using the stdClass later in the code as well and it's more flexible for me. Of course I could convert the whole thing into an array, then sort the stuff etc., but using an object is just the best option for my code here.. Link to comment https://forums.phpfreaks.com/topic/75583-sorting-an-object-array/#findComment-382440 Share on other sites More sharing options...
trq Posted November 1, 2007 Share Posted November 1, 2007 If it was your own user defined object (and your using php5) I would suggest you make it extend ArrayObject which is part of the standard php lib. But as its not, I can only suggest you use an array. Link to comment https://forums.phpfreaks.com/topic/75583-sorting-an-object-array/#findComment-382445 Share on other sites More sharing options...
yanisdon Posted November 1, 2007 Author Share Posted November 1, 2007 Thanks. Link to comment https://forums.phpfreaks.com/topic/75583-sorting-an-object-array/#findComment-382478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.