简体   繁体   English

我如何排序数组

[英]How can I sort an array

I have this array 我有这个数组

Array (  
 [146] => Post Object ( 
 [ID] => 5664  
 [post_author] => 8  
 [post_date] => 2016-04-10 16:21:55  
 [post_content] =>
 )  

 [145] => Post Object (  
 [ID] => 5638  
 [post_author] => 7  
 [post_date] => 2016-03-17 12:23:00  
 [post_content] =>
 )
) 

I want to order my array by the numbers before "=> Post Object" . 我想通过“ => Post Object”之前的数字对数组进行排序。

ie I want that the sub-array 145 appear before 146. 即我希望子数组145出现在146之前。

Thanks 谢谢

You can use ksort function. 您可以使用kso​​rt函数。

ksort($array);

For others behaviour read the related documentation at http://php.net/manual/en/array.sorting.php 对于其他行为,请阅读http://php.net/manual/en/array.sorting.php上的相关文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM