mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 20:37:03 +02:00
moved sortArrayByKey logic into Utils::
This commit is contained in:
@@ -371,25 +371,14 @@ class TwigExtension extends \Twig_Extension implements \Twig_Extension_GlobalsIn
|
||||
*
|
||||
* @param array $input
|
||||
* @param string $filter
|
||||
* @param array|int $direction
|
||||
* @param int $direction
|
||||
* @param int $sort_flags
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function sortByKeyFilter($input, $filter, $direction = SORT_ASC)
|
||||
public function sortByKeyFilter($input, $filter, $direction = SORT_ASC, $sort_flags = SORT_REGULAR)
|
||||
{
|
||||
$output = [];
|
||||
|
||||
if (!is_array($input) || !$input) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
foreach ($input as $key => $row) {
|
||||
$output[$key] = $row[$filter];
|
||||
}
|
||||
|
||||
array_multisort($output, $direction, $input);
|
||||
|
||||
return $input;
|
||||
return Utils::sortArrayByKey($input, $filter, $direction, $sort_flags);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -966,6 +966,32 @@ abstract class Utils
|
||||
return $ordered + $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort an array by a key value in the array
|
||||
*
|
||||
* @param $array
|
||||
* @param $array_key
|
||||
* @param int $direction
|
||||
* @param int $sort_flags
|
||||
* @return array
|
||||
*/
|
||||
public static function sortArrayByKey($array, $array_key, $direction = SORT_DESC, $sort_flags = SORT_REGULAR )
|
||||
{
|
||||
$output = [];
|
||||
|
||||
if (!is_array($array) || !$array) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
foreach ($array as $key => $row) {
|
||||
$output[$key] = $row[$array_key];
|
||||
}
|
||||
|
||||
array_multisort($output, $direction, $sort_flags, $array);
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get's path based on a token
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user