Codeigniter sorts by array date

i combine my array, then I want to sort them by date, but my credits and calls have different names in the date

heres my merge code

$loan = $this->db->get('loans')->result_array(); $coll = $this->db->get('collectables')->result_array(); $result = array_merge($loan, $coll); 

and heres output

 Array ( [0] => Array ( [loan_id] => 175 [loan_fullname] => Albano, Zester Quinn [loan_amount] => 15000 [loan_interest] => 2 [loan_date] => 2017-05-30 [loan_total_amount] => 15300 [loan_collectables] => 1 [loan_user_id] => 30 ) [1] => Array ( [loan_id] => 176 [loan_fullname] => Amamio, Alyanna [loan_amount] => 15000 [loan_interest] => 2 [loan_date] => 2017-05-31 [loan_total_amount] => 15300 [loan_collectables] => 2 [loan_user_id] => 32 ) [2] => Array ( [coll_id] => 92 [coll_date] => 2017-05-30 [coll_amount] => 15300 [coll_loan_id] => 175 [coll_user_id] => 30 ) [3] => Array ( [coll_id] => 93 [coll_date] => 2017-05-28 [coll_amount] => 7650 [coll_loan_id] => 176 [coll_user_id] => 32 ) [4] => Array ( [coll_id] => 94 [coll_date] => 2017-06-21 [coll_amount] => 7650 [coll_loan_id] => 176 [coll_user_id] => 32 ) ) 

but i want to sort them by date .. any ideas? thanks

+5
source share
1 answer

Hello, yes, you cannot sort arrays by date, you need to use the asort function (if you want to do an upward sort), user arsort (if you want to do a sort sort). here is an example that will make you understand.

 $age = array("Peter"=>"2017-05-30", "Ben"=>"2017-01-31", "Joe"=>"2017-05-30"); asort($age); foreach($age as $x => $x_value) { echo "Key=" . $x . ", Value=" . $x_value; echo "<br>"; } 
+5
source

Source: https://habr.com/ru/post/1268319/


All Articles