I need to sort my array value in asc order using PHP. I am explaining my code below.
$data=[
{"restaurant_name":"The Garage Sports Bar","distance":"0.48Km"},
{"restaurant_name":"A&P Chinese Food Express","distance":"8.81Km"},
{"restaurant_name":"Green Chilli","distance":"19.37Km"},
{"restaurant_name":"Pulcinella - Authentic Napoletana Pizza","distance":"1.31Km"}
]
I have above data to sort in asc order My php code is given below.
$sortArray = array();
foreach($data as $person){
foreach($person as $key=>$value){
if(!isset($sortArray[$key])){
$sortArray[$key] = array();
}
$sortArray[$key][] = $value;
}
}
$orderby = "distance";
array_multisort($sortArray[$orderby],SORT_ASC,$data);
After sorting it I am getting the following output.
$data=[{"restaurant_name":"The Garage Sports Bar","distance":"0.48Km"},{"restaurant_name":"Pulcinella - Authentic Napoletana Pizza","distance":"1.31Km"},{"restaurant_name":"Green Chilli","distance":"19.37Km"},{"restaurant_name":"A&P Chinese Food Express","distance":"8.81Km"}]
But it could not be sort properly in ASC order.