private function findNearestCommand($commandName, array $commands)
    {
        $distances = [];
        foreach (array_keys($commands) as $command) {
            $distances[$command] = levenshtein($commandName, $command);
        }

        $distances = array_filter(array_unique($distances), function ($distance) {
            return $distance <= 3;
        });

        if (empty($distances)) {
            return false;
        }

        return array_search(min($distances), $distances);
    }
private function findNearestCommand($commandName, array $commands)
    {
        $distances = [];
        foreach (array_keys($commands) as $command) {
            $distances[$command] = levenshtein($commandName, $command);
        }

        $distances = array_filter(array_unique($distances), function ($distance) {
            return $distance <= 3;
        });

        if (empty($distances)) {
            return false;
        }

        return array_search(min($distances), $distances);
    }
private function findNearestCommand ( $ commandName , array $ commands ) { $ distances = [ ] ; foreach ( array_keys ( $ commands ) as $ command ) { $ distances [ $ command ] = levenshtein ( $ commandName , $ command ) ; } $ distances = array_filter ( array_unique ( $ distances ) , function ( $ distance ) { return $ distance <= 3 ; } ) ; if ( empty ( $ distances ) ) { return false ; } return array_search ( min ( $ distances ) , $ distances ) ; }
Get the closest command to the one typed, but only if there is 3 or less
characters different

@param string $commandName
@param array $commands
@return string|false
Get the closest command to the one typed but only if there is 3 or less characters different