24 public static function sortByColumn(array &$array, $columns, $callbacks =
'', $defaultValueIfNotSetValue =
null, $preserveKeys =
false)
27 if (!is_array($columns))
29 $columns = array($columns => SORT_ASC);
31 $params = $preserveDataKeys = array();
32 $alreadyFillPreserveDataKeys =
false;
33 foreach ($columns as $column => &$order)
37 if(is_array($callbacks) && !is_callable($callbacks))
40 if(!empty($callbacks[$column]))
42 $callback = is_callable($callbacks[$column])? $callbacks[$column] :
false;
46 elseif(!empty($callbacks))
48 $callback = is_callable($callbacks)? $callbacks :
false;
51 if($callback ===
false)
53 throw new \Bitrix\Main\ArgumentOutOfRangeException(
'callbacks');
57 $valueColumn[$column] = array();
58 foreach ($array as $index => $row)
60 $value = $row[$column] ?? $defaultValueIfNotSetValue;
63 $value = call_user_func_array($callback, array($value));
65 $valueColumn[$column][$index] = $value;
66 if($preserveKeys && !$alreadyFillPreserveDataKeys)
68 $preserveDataKeys[$index] = $index;
72 $alreadyFillPreserveDataKeys = $preserveKeys && !empty($preserveDataKeys);
74 $params[] = &$valueColumn[$column];
75 $order = (array)$order;
76 foreach ($order as $i => $ord)
78 $params[] = &$columns[$column][$i];
81 unset($order, $column);
85 $params[] = &$preserveDataKeys;
88 call_user_func_array(
'array_multisort', $params);
92 $array = array_combine(array_values($preserveDataKeys), array_values($array));
110 $argCount = func_num_args();
111 for ($i = 0; $i < $argCount; $i += 2)
113 $anArray = func_get_arg($i);
114 $key = func_get_arg($i+1);
117 $current = &$anArray;
121 if (!is_array($current) || !array_key_exists($k, $current))
126 $current = &$current[$k];
130 if (is_array($current) || is_object($current) || $current !=
"")
134 elseif (is_array($anArray) && array_key_exists($key, $anArray))
136 if (is_array($anArray[$key]) || is_object($anArray[$key]) || $anArray[$key] !=
"")
137 return $anArray[$key];
191 public static function clone(array $originalArray): array
194 foreach ($originalArray as $index => $value)
196 if (is_array($value))
198 $value = static::clone($value);
200 elseif (is_object($value))
202 $value =
clone $value;
205 $clonedArray[$index] = $value;
229 $subKey = array_shift($key);
231 if (array_key_exists($subKey, $value))
233 $value = $value[$subKey];
260 $reference =& $array;
263 $subKey = array_shift($key);
265 if (!array_key_exists($subKey, $reference))
267 $reference[$subKey] = [];
269 $reference = &$reference[$subKey];
291 $reference =& $array;
294 $subKey = array_shift($key);
296 if (!array_key_exists($subKey, $reference))
304 unset($reference[$subKey]);
308 $reference = &$reference[$subKey];