Sort child elements from the menu array
@param array $array This should be a menu item array
@return array
323242
protected static function sortChildElements($array) {
        foreach($array as $i => $item){
            if(isset($item['children']) && is_array($item['children'])){
                uasort($array[$i]['children'], 'self::sortByOrder');
                $array[$i]['children'] = array_values(self::sortChildElements($array[$i]['children']));
            }
        }
        return $array;
    }
216242
public static function asort(array &$array, int $sort_flags = SORT_REGULAR): void
    {
        self::decorateOriginalArray($array);
        uasort($array, function ($a, $b) use ($sort_flags) {
            if ($a[1] == $b[1])
                return $a[0] - $b[0];
            $arr = [
                - 1 => $a[1],
                1 => $b[1]
            ];
            asort($arr, $sort_flags);
            reset($arr);
            return key($arr);
        });
        self::undecorateSortedArray($array);
    }
74326
protected function stableWeightSort(array &$array)
    {
        foreach ($array as $i => &$value) {
            $value["key"] = $i;
        }
        unset($value);

        usort($array, function(array $v1, array $v2) {
            $byWeight = $v1["weight"] - $v2["weight"];
            if ($byWeight === 0) {
                return $v1["key"] - $v2["key"];
            }
            return $byWeight;
        });
    }
1332324
public static function mergeSort($array): array
    {
        if (count($array) === 1) {
            return $array;
        }

        $middle = (int)round(count($array) / 2);
        $left = array_slice($array, 0, $middle);
        $right = array_slice($array, $middle);

        $left = self::mergeSort($left);
        $right = self::mergeSort($right);

        return self::merge($left, $right);
    }
627679
public static function ksortRecursive(array &$array, $sortFlags = SORT_REGULAR)
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return null;
        }

        $effect = &$array;
        ksort($effect, $sortFlags);

        foreach ($effect as &$value) {
            if (is_array($value)) {
                ksort($value, $sortFlags);
            }
        }

        return $effect;
    }
1020841
private function sortByWeight(array $adminMenu): array
    {
        usort($adminMenu, function ($a, $b) {
            if (!array_key_exists('priority', $a)) {
                $a['priority'] = 0;
            }

            if (!array_key_exists('priority', $b)) {
                $b['priority'] = 0;
            }

            return $b['priority'] <=> $a['priority'];
        });

        foreach ($adminMenu as &$item) {
            if (array_key_exists('children', $item)) {
                $item['children'] = $this->sortByWeight($item['children']);
            }
        }

        return $adminMenu;
    }
1269565
public static function cleanupArray($array)
    {
        $newArray = [];

        $array = static::toArray($array);

        foreach ($array as $key => $val) {

            if (is_array($val)) {
                $val = static::cleanupArray($val);
            } else {
                $val = trim($val);
                if (!$val) {
                    continue;
                }
            }

            $newArray[$key] = $val;
        }

        return $newArray;
    }
898735
public static function pivotFromTwoDimension(&$array)
    {
        foreach ((array) $array as $val) {
            if (is_array($val) || is_object($val)) {
                foreach ((array) $val as $key => $val2) {
                    $array = Arr::set($array, $key, $val2);
                }
            }
        }

        return $array;
    }
1295173
public function convertArrayToDotNotation(array $array)
    {
        $recursiveIterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));

        $newArray = [];

        foreach ($recursiveIterator as $leafValue) {
            $keys = [];

            foreach (range(0, $recursiveIterator->getDepth()) as $depth) {
                $keys[] = $recursiveIterator->getSubIterator($depth)->key();
            }

            $newArray[implode('.', $keys)] = $leafValue;
        }

        return $newArray;
    }
1300364
protected function arrayToTable(array $array)
    {
        list($keys, $values) = array_divide($array);

        return collect($keys)->zip(collect($values))->toArray();
    }
596005
public static function flatten(array $array)
    {
        $result = array();

        array_walk_recursive($array, function ($value, $key) use (& $result) {
            if (is_numeric($key) or is_object($value)) {
                $result[] = $value;
            } else {
                $result[$key] = $value;
            }
        });

        return $result;
    }
96430
private static function sortByWeights(array &$array) {
    uasort($array, function ($a, $b) {
      $a_weight = isset($a['weight']) ? $a['weight'] : 0;
      $b_weight = isset($b['weight']) ? $b['weight'] : 0;

      if ($a_weight == $b_weight) {
        return ($a['label'] > $b['label']) ? 1 : -1;
      }
      return ($a_weight > $b_weight) ? 1 : -1;
    });
  }
521680
public function sortPClasses(&$array)
    {
        if (!is_array($array)) {
            //Input is not an array!
            $array = array();
            return;
        }
        //Sort pclasses array after natural sort (natcmp)
        if (!function_exists('pcCmp')) {
            /**
             * Comparison function
             *
             * @param KlarnaPClass $a object 1
             * @param KlarnaPClass $b object 2
             *
             * @return int
             */
            function pcCmp($a, $b)
            {
                if ($a->getDescription() == null
                    && $b->getDescription() == null
                ) {
                    return 0;
                } else if ($a->getDescription() == null) {
                    return 1;
                } else if ($b->getDescription() == null) {
                    return -1;
                } else if ($b->getType() === 2 && $a->getType() !== 2) {
                    return 1;
                } else if ($b->getType() !== 2 && $a->getType() === 2) {
                    return -1;
                }

                return strnatcmp($a->getDescription(), $b->getDescription())*-1;
            }
        }
        usort($array, "pcCmp");
    }
1116251
private function recursiveSort(array &$element)
    {
        foreach ($element as &$value) {
            if (is_array($value)) {
                $this->recursiveSort($value);
            }
        }

        uasort($element, function (
            Translation $a,
            Translation $b
        ) {
            return strcmp($a->getKey(), $b->getKey());
        });
    }
818289
public static function aasort(&$array, $key)
    {
        $sorter = [];
        $ret    = [];
        reset($array);
        foreach ($array as $ii => $va)
        {
            $sorter[$ii] = $va[$key];
        }
        asort($sorter);
        foreach ($sorter as $ii => $va)
        {
            $ret[$ii] = $array[$ii];
        }
        $array = $ret;
    }
79110
public function arrayKeysSnakeRecursive($array)
    {
        $result = [];

        $array = arrayable($array) ? $array->toArray() : $array;

        array_walk($array, function ($value, $key) use (&$result) {
            $result[snake_case($key)] = arrayable($value) || is_array($value)
                ? $this->arrayKeysSnakeRecursive($value)
                : $value;
        });

        return coollect($result);
    }
1146570
static protected function flattenArray( $array )
    {
        if ( !is_array( $array ) )
        {
            return array( $array );
        }

        $arrayFlatten = array();
        while( !empty( $array ) )
        {
             $item = array_shift( $array );
             if ( is_array( $item ) )
                 $array = array_merge( $item, $array );
             else
                 $arrayFlatten[] = $item;
        }
        return $arrayFlatten;
    }