php sort properties of object
Posted
by lannoo
on Stack Overflow
See other posts from Stack Overflow
or by lannoo
Published on 2010-05-31T10:30:48Z
Indexed on
2010/05/31
10:32 UTC
Read the original article
Hit count: 217
I want to sort the properties of an object so I can loop through them in a defined order.
for example: I have an object 'book' with the following properties: 'id', 'title', 'author', 'date'.
Now i want to loop through these properties like this:
foreach($book as $prop=>$val)
//do something
now the order of the loop has to be 'title', then 'author', 'date' and 'id'
How would one do this? (I can't change the order of the properties in the class of the object because there arent any properties defined there, I get the object from the database with 'MyActiveRecord')
© Stack Overflow or respective owner