<code>$test=array(60) {
[0]=> object(stdClass)#14 (3) { ["id"]=> string(3) "609" ["title"]=> string(19) "Physical Mechanisms" ["publish_time"]=> string(10) "6 MAY 2016" }
[1]=> object(stdClass)#14 (3) { ["id"]=> string(3) "610" ["title"]=> string(20) "Engineering Substrate" ["publish_time"]=> string(10) "2 MAY 2016" }
...}
</code>根据publish_time对$test进行排序,怎么做?请教!
<code>$test=array(60) {
[0]=> object(stdClass)#14 (3) { ["id"]=> string(3) "609" ["title"]=> string(19) "Physical Mechanisms" ["publish_time"]=> string(10) "6 MAY 2016" }
[1]=> object(stdClass)#14 (3) { ["id"]=> string(3) "610" ["title"]=> string(20) "Engineering Substrate" ["publish_time"]=> string(10) "2 MAY 2016" }
...}
</code>根据publish_time对$test进行排序,怎么做?请教!
可以用php函数 usort 自定义排序
<code><?php
function _usort($a, $b) {
if ( strtotime($a->publish_time) < strtotime($a->publish_time) ) {
return -1;
} else if( strtotime($a->publish_time) > strtotime($a->publish_time) ){
return 1;
} else {
return 0;
}
}
usort($arr, '_usort');</code>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号