Skip to content
Advertisement

Sort json array by value using PHP

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.

JavaScript

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 ?

Advertisement

Answer

I think it might work if you loop over your objects with foreach.

JavaScript

Code has now been tested, because you provided the data objects.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement