Are there any best practices for creating custom sorting algorithms in PHP?

When creating custom sorting algorithms in PHP, it is important to consider factors such as efficiency, readability, and maintainability. One common approach is to implement well-known sorting algorithms such as bubble sort, merge sort, or quicksort. It is also recommended to thoroughly test the custom sorting algorithm with various input data to ensure its correctness and performance.

// Custom sorting algorithm using bubble sort
function customSort(array $arr): array {
    $n = count($arr);
    for ($i = 0; $i < $n - 1; $i++) {
        for ($j = 0; $j < $n - $i - 1; $j++) {
            if ($arr[$j] > $arr[$j + 1]) {
                $temp = $arr[$j];
                $arr[$j] = $arr[$j + 1];
                $arr[$j + 1] = $temp;
            }
        }
    }
    return $arr;
}

// Example usage
$data = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5];
$sortedData = customSort($data);
print_r($sortedData);