This document lists all the functions available in the Valksor Functions: Sort package.
public function bubbleSort(
array &$array,
): voidSorts an array in place using the bubble sort algorithm.
Parameters:
$array: The array to sort (passed by reference)
public function mergeSort(
array $array,
): arraySorts an array using the merge sort algorithm.
Parameters:
$array: The array to sort
Returns a new sorted array.
public function merge(
array $left,
array $right,
): arrayMerges two sorted arrays into a single sorted array.
Parameters:
$left: The first sorted array$right: The second sorted array
Returns a new sorted array containing all elements from both input arrays.
public function sortByParameter(
array|object $data,
string $parameter,
string $order = 'ASC',
): object|arraySorts an array or object by a specific parameter.
Parameters:
$data: The array or object to sort$parameter: The parameter to sort by$order: The sort order ('ASC' or 'DESC')
Returns the sorted array or object.
Throws an InvalidArgumentException if the parameter doesn't exist in the sortable variable.
public function stableSort(
array $elements,
callable $getComparedValue,
callable $compareValues,
): arrayPerforms a stable sort on an array of elements.
Parameters:
$elements: The array to sort$getComparedValue: A callable that extracts the value to compare from an element$compareValues: A callable that compares two values and returns an integer (-1, 0, or 1)
Returns a new sorted array.
public function usort(
string $parameter,
string $order,
): ClosureCreates a closure for use with PHP's usort function to sort arrays or objects by a specific parameter.
Parameters:
$parameter: The parameter to sort by$order: The sort order ('ASC' or 'DESC')
Returns a closure that can be used with usort.