usage:

$devices_array_sorted = ArrayOfArraysSort($devices_array, "AverageWatts",SORT_ASC);

the function:

/* sort array that contains a lot of arrays by key */
function ArrayOfArraysSort($array,$key,$mode)
{
    // sort by age
    $sort = array();
    foreach($array as $k=>$v) {
        $sort[$key][$k] = $v[$key];
    }
    # sort by age desc and then title asc
    array_multisort($sort[$key], $mode,$array);
    
    return $array;
}

where example array is:

Array
(
    [0] => Array
        (
            [id] => 1
            [category] => 3
            [brand] => 2
            [model] => t440
            [name] => lenovo t440
            [modes] => 1
            [happiness] => 4
            [works_since_years] => 4
            [description] => 
            [my_comment] => 
            [image] => 
            [AverageWatts] => 62.5
        )

    [1] => Array
        (
            [id] => 2
            [category] => 3
            [brand] => 7
            [model] => xps
            [name] => dell xps
            [modes] => 1,2,3
            [happiness] => 3
            [works_since_years] => 2
            [description] => 
            [my_comment] => 
            [image] => 
            [AverageWatts] => 85
        )

)

liked this article?

  • only together we can create a truly free world
  • plz support dwaves to keep it up & running!
  • (yes the info on the internet is (mostly) free but beer is still not free (still have to work on that))
  • really really hate advertisement
  • contribute: whenever a solution was found, blog about it for others to find!
  • talk about, recommend & link to this blog and articles
  • thanks to all who contribute!
admin