42 $ilDB = $DIC->database();
45 if (!is_array($a_array) or !count($a_array)) {
49 foreach ($a_array as $k => $item) {
50 $a_array[$k] =
$ilDB->quote($item);
62 if (is_array($a_data)) {
63 foreach ($a_data as $k => $v) {
80 public static function stripSlashesArray(array $a_arr,
bool $a_strip_html =
true,
string $a_allow =
""): array
82 foreach ($a_arr as $k => $v) {
94 string $a_array_sortby_key,
95 string $a_array_sortorder =
"asc",
96 bool $a_numeric =
false,
97 bool $a_keep_keys =
false 100 return self::stableSortArray($array, $a_array_sortby_key, $a_array_sortorder, $a_numeric);
103 global $array_sortby, $array_sortorder;
104 $array_sortby = $a_array_sortby_key;
106 if ($a_array_sortorder ==
"desc") {
107 $array_sortorder =
"desc";
109 $array_sortorder =
"asc";
113 uasort($array, [ilArrayUtil::class,
"sort_func_numeric"]);
115 usort($array, [ilArrayUtil::class,
"sort_func_numeric"]);
119 uasort($array, [ilArrayUtil::class,
"sort_func"]);
121 usort($array, [ilArrayUtil::class,
"sort_func"]);
133 global $array_sortby, $array_sortorder;
135 if (!isset($array_sortby)) {
140 $leftValue = (string) ($left[$array_sortby] ??
'');
141 $rightValue = (string) ($right[$array_sortby] ??
'');
145 if ($array_sortorder ===
"asc") {
147 } elseif ($array_sortorder ===
"desc") {
159 global $array_sortby, $array_sortorder;
161 $leftValue = (string) ($left[$array_sortby] ??
'');
162 $rightValue = (string) ($right[$array_sortby] ??
'');
164 if ($array_sortorder ===
"asc") {
165 return $leftValue <=> $rightValue;
166 } elseif ($array_sortorder ===
"desc") {
167 return $rightValue <=> $leftValue;
178 private static function mergesort(array &$array, ?callable $cmp_function =
null): void
180 if ($cmp_function ===
null) {
181 $cmp_function =
'strcmp';
184 if (count($array) < 2) {
189 $halfway = intval(count($array) / 2);
190 $array1 = array_slice($array, 0, $halfway);
191 $array2 = array_slice($array, $halfway);
198 if (call_user_func($cmp_function, end($array1), $array2[0]) < 1) {
199 $array = array_merge($array1, $array2);
206 while ($ptr1 < count($array1) && $ptr2 < count($array2)) {
207 if (call_user_func($cmp_function, $array1[$ptr1], $array2[$ptr2]) < 1) {
208 $array[] = $array1[$ptr1++];
210 $array[] = $array2[$ptr2++];
215 while ($ptr1 < count($array1)) {
216 $array[] = $array1[$ptr1++];
218 while ($ptr2 < count($array2)) {
219 $array[] = $array2[$ptr2++];
232 string $a_array_sortby,
233 string $a_array_sortorder =
"asc",
234 bool $a_numeric =
false 236 global $array_sortby, $array_sortorder;
238 $array_sortby = $a_array_sortby;
240 if ($a_array_sortorder ==
"desc") {
241 $array_sortorder =
"desc";
243 $array_sortorder =
"asc";
247 $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 sort_func_numeric(array $left, array $right)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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 mergesort(array &$array, ?callable $cmp_function=null)
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)