[Solved] how to convert array to ArrayObject with php from json file


To read the data

$unsortedData = json_decode(file_get_contents("data.json"), true);

the second paramater true make you get an associative array, instead of getting an array of objects (stdclass)

to sort the array:

usort($unsortedData,  function($a, $b){
    return $a['serial'] < $b['serial'];
});

usort will sort the data according the callback passed as the second parameter, so you can customize it

1

solved how to convert array to ArrayObject with php from json file