43 $ilDB = $DIC->database();
46 if (!is_array($a_array) or !count($a_array)) {
50 foreach ($a_array as $k => $item) {
51 $a_array[$k] =
$ilDB->quote($item);
64 if (is_array($a_data)) {
65 foreach ($a_data as $k => $v) {
82 public static function stripSlashesArray(array $a_arr,
bool $a_strip_html =
true,
string $a_allow =
""): array
84 foreach ($a_arr as $k => $v) {
96 string $a_array_sortby_key,
97 string $a_array_sortorder =
"asc",
98 bool $a_numeric =
false,
99 bool $a_keep_keys =
false 102 return self::stableSortArray($array, $a_array_sortby_key, $a_array_sortorder, $a_numeric);
105 global $array_sortby, $array_sortorder;
106 $array_sortby = $a_array_sortby_key;
108 if ($a_array_sortorder ==
"desc") {
109 $array_sortorder =
"desc";
111 $array_sortorder =
"asc";
115 uasort($array, [ilArrayUtil::class,
"sort_func_numeric"]);
117 usort($array, [ilArrayUtil::class,
"sort_func_numeric"]);
121 uasort($array, [ilArrayUtil::class,
"sort_func"]);
123 usort($array, [ilArrayUtil::class,
"sort_func"]);
135 global $array_sortby, $array_sortorder;
137 if (!isset($array_sortby)) {
142 $leftValue = (string) ($left[$array_sortby] ??
'');
143 $rightValue = (string) ($right[$array_sortby] ??
'');
147 if ($array_sortorder ===
"asc") {
149 } elseif ($array_sortorder ===
"desc") {
161 global $array_sortby, $array_sortorder;
163 $leftValue = (string) ($left[$array_sortby] ??
'');
164 $rightValue = (string) ($right[$array_sortby] ??
'');
166 if ($array_sortorder ===
"asc") {
167 return $leftValue <=> $rightValue;
168 } elseif ($array_sortorder ===
"desc") {
169 return $rightValue <=> $leftValue;
180 private static function mergesort(array &$array, callable $cmp_function = null): void
182 if ($cmp_function === null) {
183 $cmp_function =
'strcmp';
186 if (count($array) < 2) {
191 $halfway = count($array) / 2;
192 $array1 = array_slice($array, 0, $halfway);
193 $array2 = array_slice($array, $halfway);
200 if (call_user_func($cmp_function, end($array1), $array2[0]) < 1) {
201 $array = array_merge($array1, $array2);
208 while ($ptr1 < count($array1) && $ptr2 < count($array2)) {
209 if (call_user_func($cmp_function, $array1[$ptr1], $array2[$ptr2]) < 1) {
210 $array[] = $array1[$ptr1++];
212 $array[] = $array2[$ptr2++];
217 while ($ptr1 < count($array1)) {
218 $array[] = $array1[$ptr1++];
220 while ($ptr2 < count($array2)) {
221 $array[] = $array2[$ptr2++];
234 string $a_array_sortby,
235 string $a_array_sortorder =
"asc",
236 bool $a_numeric =
false 238 global $array_sortby, $array_sortorder;
240 $array_sortby = $a_array_sortby;
242 if ($a_array_sortorder ==
"desc") {
243 $array_sortorder =
"desc";
245 $array_sortorder =
"asc";
249 $sort_array = array_values($array);
static sort_func(array $left, array $right)
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
static quoteArray(array $a_array)
Quotes all members of an array for usage in DB query statement.
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static mergesort(array &$array, callable $cmp_function=null)
static sort_func_numeric(array $left, array $right)
static stableSortArray(array $array, string $a_array_sortby, string $a_array_sortorder="asc", bool $a_numeric=false)
Sort an aray using a stable sort algorithm, which preveserves the sequence of array elements which ha...
static strCmp(string $a, string $b)
static stripSlashesArray(array $a_arr, bool $a_strip_html=true, string $a_allow="")
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)