public function map(array $requested, array $supported): array
    {
        $index = [];
        foreach ($supported as $tag) {
            $key = strtolower(preg_replace('/_-\./', '', $tag));
            $index[$key] = $tag;
        }

        $result = [];
        foreach ($requested as $source) {
            if (array_key_exists($source, $this->preferred)) {
                $preferred = $this->preferred[$source];
                foreach ($preferred as $tag) {
                    if (in_array($tag, $supported, true)) {
                        $result[] = $tag;
                        continue 2;
                    }
                }
            }

            if (in_array($source, $supported, true)) {
                $result[] = $source;
                continue;
            }

            $tag = strtolower(preg_replace('/_-\./', '', $source));
            foreach ($index as $key => $target) {
                if (strpos($key, $tag) === 0) {
                    $result[] = $target;
                    break;
                }
            }
        }

        return $result;
    }
public function map(array $requested, array $supported): array
    {
        $index = [];
        foreach ($supported as $tag) {
            $key = strtolower(preg_replace('/_-\./', '', $tag));
            $index[$key] = $tag;
        }

        $result = [];
        foreach ($requested as $source) {
            if (array_key_exists($source, $this->preferred)) {
                $preferred = $this->preferred[$source];
                foreach ($preferred as $tag) {
                    if (in_array($tag, $supported, true)) {
                        $result[] = $tag;
                        continue 2;
                    }
                }
            }

            if (in_array($source, $supported, true)) {
                $result[] = $source;
                continue;
            }

            $tag = strtolower(preg_replace('/_-\./', '', $source));
            foreach ($index as $key => $target) {
                if (strpos($key, $tag) === 0) {
                    $result[] = $target;
                    break;
                }
            }
        }

        return $result;
    }
public function map ( array $ requested , array $ supported ) : array { $ index = [ ] ; foreach ( $ supported as $ tag ) { $ key = strtolower ( preg_replace ( '/_-\./' , '' , $ tag ) ) ; $ index [ $ key ] = $ tag ; } $ result = [ ] ; foreach ( $ requested as $ source ) { if ( array_key_exists ( $ source , $ this -> preferred ) ) { $ preferred = $ this -> preferred [ $ source ] ; foreach ( $ preferred as $ tag ) { if ( in_array ( $ tag , $ supported , true ) ) { $ result [ ] = $ tag ; continue 2 ; } } } if ( in_array ( $ source , $ supported , true ) ) { $ result [ ] = $ source ; continue ; } $ tag = strtolower ( preg_replace ( '/_-\./' , '' , $ source ) ) ; foreach ( $ index as $ key => $ target ) { if ( strpos ( $ key , $ tag ) === 0 ) { $ result [ ] = $ target ; break ; } } } return $ result ; }
Map given list of language tags to supported ones

@param string[] $requested list of requested languages
@param string[] $supported list of supported languages

@return string[]

@link  http://tools.ietf.org/html/bcp47
@since 1.0
Map given list of language tags to supported ones