Jump to content

sorting mulidimensional array by value?


zander1983

Recommended Posts

I have an array and when i do a print_r(), i get this:

 

Array ( [0] => Array ( [path] => 1 [order] => 2 ) [1] => Array ( [path] => 2 [order] => 2 ) [2] => Array ( [path] => 3 [order] => 1 ) )

 

I want to sort it so that the array with an order of 1 is at the front, i.e. that last array in this case. I tried asort but that didnt do anything...

Link to comment
https://forums.phpfreaks.com/topic/249730-sorting-mulidimensional-array-by-value/
Share on other sites

got it, i used this:

 

<?php
     // Sort the multidimensional array
     usort($results, "custom_sort");
     // Define the custom sort function
     function custom_sort($a,$b) {
          return $a['some_sub_var']>$b['some_sub_var'];
     }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.