I am trying to sort the array using usort().But my function does not seem to work. I want to sort it by partners_order of each object i.e, $myJson[0] and then $myJson1 separately
The Json array is decoded using $myJson = json_decode($jsonData);
PHP function to sort is written below.
usort($myJson, function($a, $b) {
return $a->partners->partners_order < $b->partners->partners_order ? -1 : 1;
});
Due to restrictions in this site, I cant post the array here. Hence I am forced to use 3rd party site fiddle https://jsfiddle.net/z8s18c21/
any help please ?
$a->partners->partners_orderthepartnersbit is an array. You have to use a key. We cannot answer your question because it is unclear how the sorting should be done.partners_orderof each object i.e, $myJson[0] and then $myJson[1] separately