public static function median($arr)
    {
        $vals = array_values($arr);
        sort($vals);
        
        $num_vals = count($vals);
        return ($num_vals % 2)
            ? ($vals[$num_vals / 2] + $vals[($num_vals / 2) + 1]) / 2
            : $vals[($num_vals + 1) / 2];
    }