简体   繁体   中英

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" .

ie I want that the sub-array 145 appear before 146.

Thanks

You can use ksort function.

ksort($array);

For others behaviour read the related documentation at http://php.net/manual/en/array.sorting.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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