Php small white array solution resorts the array based on a certain key value to give a json Array such as 100
[{"Id": "1", "name": "21g", "dis": "33 "},
{"Id": "2", "name": "21g", "dis": "22 "},
{"Id": "3", "name": "21g", "dis": "3 "},
{"Id": "4", "name": "21g", "dis": "5 "},
{"Id": "5", "name": "21g", "dis": "12"}]
Sort by dis in ascending order
[{"Id": "3", "name": "21g", "dis": "3 "},
{"Id": "4", "name": "21g", "dis": "5 "},
{"Id": "5", "name": "21g", "dis": "12 "},
{"Id": "2", "name": "21g", "dis": "22 "},
{"Id": "1", "name": "21g", "dis": "33"}]
Please wait for the step details !!!
Reply to discussion (solution)
$s =<<< TXT[ {"id":"1","name":"21g","dis":"33"}, {"id":"2","name":"21g","dis":"22"}, {"id":"3","name":"21g","dis":"3"}, {"id":"4","name":"21g","dis":"5"}, {"id":"5","name":"21g","dis":"12"}] TXT;$a = json_decode($s, true);foreach($a as $v) $r[] = $v['dis'];array_multisort($r, $a);echo json_encode($a);
[{"Id": "3", "name": "21g", "dis": "3" },{ "id": "4 ", "name": "21g", "dis": "5" },{ "id": "5", "name": "21g", "dis ": "12" },{ "id": "2", "name": "21g", "dis": "22" },{ "id ": "1", "name": "21g", "dis": "33"}]
Thank you !! It's done!