public static function sortByPriority($accept)
    {
        if ($accept == '') {
            return array();
        }

        $tmp_accept_list = array();
        $accepts = explode(',', strtolower($accept));

        foreach ($accepts as $pos => $accept) {
            $parts = explode(';q=', trim($accept));
            $type = $parts[0];
            $quality = isset($parts[1]) ? floatval($parts[1]) : 1;
            $tmp_accept_list[] = array('type' => $type, 'quality' => $quality);
        }

        // Attention: $acceptList has to be decorated since all PHP sorting functions aren't stable
        // for more information a deeper explamentation of the issue, have a look here:
        // @see http://stackoverflow.com/questions/17364127/reference-all-basic-ways-to-sort-arrays-and-data-in-php/17365409#17365409
        array_walk($tmp_accept_list, function (&$element, $index) {
            $element = array($element, $index); // decorate
        });
        usort($tmp_accept_list, function ($a, $b) {
            // $a[0] and $b[0] contain the primary sort key
            // $a[1] and $b[1] contain the secondary sort key
            $tmp = strcmp($b[0]['quality'], $a[0]['quality']); // a<=>b swapped, because reveresed sort

            if ($tmp != 0) {
                return $tmp; // use primary key comparison results
            }

            return $a[1] - $b[1]; // use secondary key
        });

        array_walk($tmp_accept_list, function (&$element) {
            $element = $element[0];
        });

        $output = array();
        foreach ($tmp_accept_list as $accept_entry) {
            $type = $accept_entry['type'];
            $quality = $accept_entry['quality'];
            $output[$type] = $quality;
        }

        return $output;
    }