Skip to content
Advertisement

Sort results from high to low float array – wordpress

Maybe this should be very easy but I am a bit lost on how to sort this data in a good way.

I got this query in a WordPress template to get some post_meta:

JavaScript

With the data I get from this query get some more info and I want to final result sorted from High to Low.

JavaScript

I got $name_provider; and $gemiddeld_totaal; and I want the results to orderby $gemiddeld_totaal; from high to low. I tried a bunch of things but no luck so far. It is a float array and for some reason I am not able to sort the results.

This is a part of the var_dump of $gemiddeld_totaal;:

JavaScript

How can I sort the results by $gemiddeld_totaal;? And the field $name_provider; also should sort with the sorting of $gemiddeld_totaal;.

EDIT The results shoud look like:

JavaScript

EDIT 2 (adding one more data field) In de foreach ( $pages as $page ) { I got one more data field that is needed in the output of the other foreach.

JavaScript

I tried some things but cant seem to figure out how to add this. This is the new line in the foreach. Could you explain me how to do this? Maybe I will understand it better then.

Advertisement

Answer

One way of doing this is using array_multisort() the documentation says:

We have an array of rows, but array_multisort() requires an array of columns

JavaScript

Once you’ve got that part you can sort both array’s like:

JavaScript

edit To get the desired result you could use something like :

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