我有一个$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"
}
....
我对任何解决方案都感兴趣,即使我必须创建一个可以对后记进行排序的新数组等
蚂蚁的想法?谢谢