I am trying to form my array in order by date I have find my answer from this question and it is show the desire result through this answer but when I use print_r
or json_encode
it just show me true.
I don't know why?
The answer method:
function sortFunction( $a, $b ) {
return strtotime($a["date"]) - strtotime($b["date"]);
}
usort($worth_array, "sortFunction");
echo "<pre>";
var_dump($worth_array);
echo "</pre>";
Result:
array(10) {
[0]=>
array(2) {
["date"]=>
string(10) "2014-06-03"
["worth"]=>
int(1131)
}
[1]=>
array(2) {
["date"]=>
string(10) "2014-06-04"
["worth"]=>
int(4469)
}
}
print_r
method:
function sortFunction( $a, $b ) {
return strtotime($a["date"]) - strtotime($b["date"]);
}
$worth_array_final = usort($worth_array, "sortFunction");
echo "<pre>";
print_r($worth_array_final);
echo "</pre>";
Result: 1