protected function sortByWeight(array $locales)
    {
        // new index
        $index = [];

        // for those who are interested in (int) or intval() whats faster:
        // http://www.entwicklerblog.net/php/php-variable-in-integer-verwandeln-intfoo-oder-intvalfoo/
        foreach ($locales as $localeSet) {
            $index[$localeSet['locale']] = (int) $localeSet['weight'];
        }

        // make values the keys
        $index = array_flip($index);

        // sort by key
        krsort($index);

        // rebuild
        $locales = [];

        foreach ($index as $weight => $locale) {
            $locales[] = [
                'locale' => $locale,
                'weight' => ($weight / 10), // restore the correct weight here -> after sorting
            ];
        }

        return $locales;
    }
protected function sortByWeight(array $locales)
    {
        // new index
        $index = [];

        // for those who are interested in (int) or intval() whats faster:
        // http://www.entwicklerblog.net/php/php-variable-in-integer-verwandeln-intfoo-oder-intvalfoo/
        foreach ($locales as $localeSet) {
            $index[$localeSet['locale']] = (int) $localeSet['weight'];
        }

        // make values the keys
        $index = array_flip($index);

        // sort by key
        krsort($index);

        // rebuild
        $locales = [];

        foreach ($index as $weight => $locale) {
            $locales[] = [
                'locale' => $locale,
                'weight' => ($weight / 10), // restore the correct weight here -> after sorting
            ];
        }

        return $locales;
    }
protected function sortByWeight ( array $ locales ) { // new index $ index = [ ] ; // for those who are interested in (int) or intval() whats faster: // http://www.entwicklerblog.net/php/php-variable-in-integer-verwandeln-intfoo-oder-intvalfoo/ foreach ( $ locales as $ localeSet ) { $ index [ $ localeSet [ 'locale' ] ] = ( int ) $ localeSet [ 'weight' ] ; } // make values the keys $ index = array_flip ( $ index ) ; // sort by key krsort ( $ index ) ; // rebuild $ locales = [ ] ; foreach ( $ index as $ weight => $ locale ) { $ locales [ ] = [ 'locale' => $ locale , 'weight' => ( $ weight / 10 ) , // restore the correct weight here -> after sorting ] ; } return $ locales ; }
This method is intend to sort the detected locales by it's weight.

@param array $locales The locales array to sort by weight

@author Benjamin Carl <opensource@clickalicious.de>

@return array By weight sorted elements
This method is intend to sort the detected locales by it s weight .