mirror of
https://git.steelants.cz/SH/PHP_SMART_HOME_V3.git
synced 2026-10-11 17:54:34 +00:00
Little Tweeks + Sort Function for array
This commit is contained in:
1 parent
a4cdb250b9
commit
5ad11cbb10
3 files changed
+31
-14
No files matched your search
@@ -178,4 +178,29 @@ class Utilities
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort Array by keys
|
||||
*
|
||||
* @param array $data
|
||||
* @param [type] $key
|
||||
* @param string $operator ('asc'/'desc')
|
||||
* @return void
|
||||
*/
|
||||
static function sortArrayByKey($data = [], $key, $operator = "asc"){
|
||||
if ($operator == "asc")
|
||||
{
|
||||
uasort($data, function($a, $b) use ($key){
|
||||
if ($a[$key] == $b[$key]) return 0;
|
||||
return ($a[$key] < $b[$key]) ? -1 : 1;
|
||||
});
|
||||
} else{
|
||||
uasort($data, function($a, $b) use ($key){
|
||||
if ($a[$key] == $b[$key]) return 0;
|
||||
return ($a[$key] > $b[$key]) ? -1 : 1;
|
||||
});
|
||||
}
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user