tags:

views:

45

answers:

1

How do I sort the "name" field in ASC and also sort in DESC ordering using only php?

$stud = json_encode($arr); print_r($stud);

output: [{"id":1, "name":"Some Name"}, {"id":4, "name":"Another Name"}, {"id":9, "name":"Third Name"}]

i need this type

$stud = [ {"id":4, "name":"Another Name"}, {"id":1, "name":"Some Name"}, {"id":9, "name":"Third Name"}];

how i sort after json_encode? tell anyone your suggestion

+4  A: 

You decode the JSON string back into PHP. Sort it using the normal PHP sort routines (looks like uksort is the right one here). Then reencode it.

Serializing data to JSON is something you do in order to transport the data, not to perform operations on it.

David Dorward