Recursive ksort function to sort array.

See: https://gist.github.com/cdzombak/601849

@param  array  $array
@return void
511752
protected function sortArray(&$array, $sort_flags = SORT_REGULAR)
    {
        if (! is_array($array)) {
            return;
        }

        ksort($array, $sort_flags);

        foreach ($array as &$arr) {
            $this->sortArray($arr, $sort_flags);
        }
    }
1267789
public static function kshuffle(&$array)
    {
        if (!is_array($array) || empty($array))
        {
            return false;
        }
        $tmp = [];
        foreach ($array as $key => $value)
        {
            $tmp[] = ['k' => $key, 'v' => $value];
        }
        shuffle($tmp);
        $array = [];
        foreach ($tmp as $entry)
        {
            $array[$entry['k']] = $entry['v'];
        }

        return true;
    }
727210
public function isSequentialArray($array)
    {
        $counter = 0;
        foreach ($array as $key => $value) {
            if ($counter !== $key) {
                return false;
            }
            $counter++;
        }

        return true;
    }
1075571
public function addParameters(array $array)
  {
    foreach ($array as $key => $val) {
      $this->addParameter($key, $val);
    }

    return $this->sortParameters();
  }
252541
public static function sortByKey($_array, $key) {
        $array = $_array;
        $result = usort($array, function($a, $b) use ($key) {
            return strcmp(call_user_func(array($a, $key)),
                          call_user_func(array($b, $key)));
        });
        if (!$result)
            throw new ArrayException("sorting by \"$key\" failed");
        return $array;
    }
890945
public function fromArray(array $array)
    {
        $this->removeAll();
        foreach ($array as $name => $values) {
            if (\is_array($values)) {
                foreach ($values as $value) {
                    $this->add($name, $value);
                }
            } else {
                $this->add($name, $values);
            }
        }
    }
1054139
protected function normalize(array &$array)
    {
        foreach ($array as $key => $value) {
            if (array_key_exists($key, self::$apcFix)) {
                unset($array[$key]);
                $array[self::$apcFix[$key]] = $value;
            }
        }
    }
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;
    }
564932
public static <E extends Comparable<E>> void sort(E[] array) {
        int minIndex = 0;
        for(int i = 0; i < array.length; i++) {
            minIndex = i;
            
            for(int j = minIndex; j < array.length; j++) {
                if(array[j].compareTo(array[minIndex]) < 0) {
                    minIndex = j;
                }
            }
            TrivialSwap.swap(array, i, minIndex);
        }
    }
1236025
public static function multisort($array, $params) {
		static::$_cache = array();
		$isNumeric = is_numeric(implode('', array_keys($array)));
		if (is_array($params)) {
			static::_normalizeParams($params);
			$callback = function($a, $b) use($params) {
				$result = 0;
				foreach ($params as $param) {
					$valA = static::_getValue($param['field'], $a);
					$valB = static::_getValue($param['field'], $b);
					if ($valA > $valB) {
						$result = 1;
					} elseif ($valA < $valB) {
						$result = -1;
					}
					if ($result !== 0) {
						if (strtolower($param['direction']) === 'desc') {
							$result *= -1;
						}
						break;
					}
				}
				return $result;
			};
			if ($isNumeric) {
				usort($array, $callback);
			} else {
				uasort($array, $callback);
			}
		} elseif (is_string($params)) {
			if ($isNumeric) {
				(strtolower($params) === 'desc') ? rsort($array) : sort($array);
			} else {
				(strtolower($params) === 'desc') ? arsort($array) : asort($array);
			}
		}
		return $array;
	}
1036492
public static function fieldSort($array, $fields)
    {
        if (!\is_array($fields)) {
            $fields = array($fields);
        }
        self::$temp = $fields;
        $i = 0;
        // restructure the array for sorting.
        //   PHP's uasort is not a "stable sort" (original order not maintained if rows are equal)
        //   if sort values are equal, will sort by temp increment value
        foreach ($array as $k => $row) {
            $array[$k] = array($i++, $row);
        }
        \uasort($array, array(__CLASS__, 'fieldSortFunc'));
        foreach ($array as $k => $row) {
            $array[$k] = $row[1];
        }
        self::$temp = null; // unset($this->temp);
        return $array;
    }
1244527
public static function array_sort(array $array, $order, $seq = '') {
    if (!$order) {
      return $array;
    }
    if (is_array($order)) {
      $key = array_keys($order)[0];
      $seq = $order[$key];
      $order = $key;
    }
    $seq = strtoupper($seq) == 'DESC' ? -1 : 1;
    usort( $array, function ($a, $b) use ($order, $seq) {
      $a = $a[$order];
      $b = $b[$order];
      $diff = is_string($a) && is_string($b) ? strcmp($a, $b) : $a - $b;
      return $seq * ceil($diff);
    });
    return $array;
  }
75986
public function sortBlocks( array $sortArray )
    {
        $sortedBlocks = array();

        foreach( $sortArray as $sortItem )
        {
            $blocksToBeRemoved = array();
            
            foreach( $this->attributes['blocks'] as $block )
            {
                if ( $block->attribute('id') === $sortItem )
                    $sortedBlocks[] = $block;
                
                if ( $block->toBeRemoved() )
                    $blocksToBeRemoved[] = $block;
            }
        }

        $sortedBlocks = array_merge( $sortedBlocks, $blocksToBeRemoved );

        $this->attributes['blocks'] = $sortedBlocks;
    }
787924
public function fillFromArray(array $array)
	{
		$array = $array + array(
			'recource' => null,
			'title' => null,
			'target' => null,
			'page_master_id' => null,
			'file_id' => null,
			'href' => null,
			'classname' => null,
		);

		$this->resource = $array['resource'];
		$this->title = $array['title'];
		$this->target = $array['target'];
		$this->pageId = $array['page_master_id'];
		$this->fileId = $array['file_id'];
		$this->href = $array['href'];
		$this->classname = $array['classname'];

		$this->pageLocalization = null;
	}
1026547
public static function ReverseSortLowest ($array, $name) {
		uasort(
			$array,
			function ($current, $next) use ($name) {
				return -1 * strnatcmp(static::GetLowest($current, $name), static::GetLowest($next, $name));
			}
		);
		return $array;
	}
1314728
public function copyFromArray(array &$array)
    {
        // sns
        $this->setSns(
            Sns::valueOf(
                LanguageUtility::getFromArray('sns', $array)));

        // apiKey
        $this->setApiKey(
            LanguageUtility::getFromArray('apiKey', $array));

        // apiSecret
        $this->setApiSecret(
            LanguageUtility::getFromArray('apiSecret', $array));
    }
1372055
private static function array_shuffle(array &$array)
    {
        for($i = count($array) - 1; $i > 0; $i--)
        {
            $j = mt_rand(0,$i);
            $temp = $array[$i];
            $array[$i] = $array[$j];
            $array[$j] = $temp;
        }
    }