When I try to do asort($data)
and then return it like response()->json($data, 200)
, the output is still in its original position.
Here's the code:
$fruits = array( 'guava', 'apple', 'orange' );
asort( $fruits );
return response()->json( $fruits, 200 );
then the output is still in its position.
{
0: "guava",
1: "apple",
2: "orange"
}
But when I try to dump the data just after the sorting happen, like
$fruits = array( 'guava', 'apple', 'orange' );
asort( $fruits );
dd( $fruits );
I'm getting the right position of data.
array:3 [
1 => "apple"
0 => "guava"
2 => "orange"
]
Any idea, why this happen? and how can I solve this? Im using Laravel 5.1