I want to parse the JSON string below into an associative array, sort it by the ‘age’ field and output the sorted array as an HTML table:
<?
$json='[{"name": "jesse","age": 25},{"name": "jason","age": 29},{"name": "johnson","age": 24}]';
?>
Should I use some sort of json_decode to print the individual values and use an existing sorting function in php?
Yes, the only way (I know of) is to use:
Php offers many array sorting functions, just browse manual. I also borrowed
objectToArrayfrom this page.I guess you will want to sort by age (or name), you should probably use
usort: