php - Sort multi-dimensional array help -


i trying sort array season_number not sure function use assume need custom sort? ideas?

array (     [0] => array         (             [season_number] => 7             [show_id] => 21             [show_seasons_id] => 14         )      [1] => array         (             [season_number] => 6             [show_id] => 21             [show_seasons_id] => 31         )      [2] => array         (             [season_number] => 1             [show_id] => 21             [show_seasons_id] => 40         )      [3] => array         (             [season_number] => 2             [show_id] => 21             [show_seasons_id] => 41         ) ) 

you can use usort function 'compare' function:

function compare_my_elements( $arr1, $arr2 ) {    $s1=$arr1["season_number"];    $s2=$arr2["season_number"];    if( $s1 == $s2 ) return 0;    return ( $s1 > $s2 ? 1 : -1 ); }  usort( $my_md_array, compare_my_elements ); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -