【发布时间】:2012-12-05 20:56:22
【问题描述】:
我有一个属性$this->result 包含一个对象:
array(40) {
[0] => object(Model)#181 (7) {
["_id":protected] => string(2) "1"
["_img":protected] => string(95) "/1273720855.jpg"
}
[1] => object(Model)#224 (7) {
["_id":protected] => string(2) "2"
["_img":protected] => string(95) "/test.jpg"
}
[2] => object(Model)#182 (7) {
["_id":protected] => string(2) "3"
["_img":protected] => string(95) "/127377775.jpg"
}
[3] => object(Model)#224 (7) {
["_id":protected] => string(2) "4"
["_img":protected] => string(95) "/test.jpg"
}
[4] => object(Model)#182 (7) {
["_id":protected] => string(2) "5"
["_img":protected] => string(95) "/129586775.jpg"
}
...
所以如果我做一个循环,我可以获得img 属性:
foreach($this->result as $val){
echo $val->getImg(); //'/1273720855.jpg'
}
我想做的是对对象进行排序,以使具有/test.jpg 的属性位于最后或最后回显它们,例如:
array(40) {
[2] => object(Model)#182 (7) {
["_id":protected] => string(2) "3"
["_img":protected] => string(95) "/127377775.jpg"
}
[4] => object(Model)#182 (7) {
["_id":protected] => string(2) "5"
["_img":protected] => string(95) "/129586775.jpg"
}
[1] => object(Model)#224 (7) {
["_id":protected] => string(2) "2"
["_img":protected] => string(95) "/test.jpg"
}
[3] => object(Model)#224 (7) {
["_id":protected] => string(2) "4"
["_img":protected] => string(95) "/test.jpg"
}
....
我对任何解决方案都感兴趣,即使我必须创建一个可以对后缀进行排序的新数组等
蚂蚁的想法?谢谢
【问题讨论】:
标签: php arrays zend-framework sorting object