public static function singular(string $word) : string
    {
        // Check that `$word` is countable.
        if(in_array($word, Inflector::$_uncontable)) {
            return $word;
        }

        // Now check that `$word` is regular.
        if(isset(Inflector::$_singular["irregular"][$word])) {
            return Inflector::$_singular["irregular"][$word];
        }

        // Now check that `$word` can be singularize.
        foreach(Inflector::$_singular["uninflected"] as $rule) {
            if(preg_match("/^". $rule ."$/", $word)) {
                return $word;
            }
        }

        // Now the word follows a rule, so apply it
        foreach(Inflector::$_singular["rules"] as $key => $value) {
            if(preg_match($key, $word)) {
                return preg_replace($key, $value, $word);
            }
        }

        // Well, right now the word couldn't be singularized
        // so return it as it was (or throw an exception?)
        return $word;
    }
public static function singular(string $word) : string
    {
        // Check that `$word` is countable.
        if(in_array($word, Inflector::$_uncontable)) {
            return $word;
        }

        // Now check that `$word` is regular.
        if(isset(Inflector::$_singular["irregular"][$word])) {
            return Inflector::$_singular["irregular"][$word];
        }

        // Now check that `$word` can be singularize.
        foreach(Inflector::$_singular["uninflected"] as $rule) {
            if(preg_match("/^". $rule ."$/", $word)) {
                return $word;
            }
        }

        // Now the word follows a rule, so apply it
        foreach(Inflector::$_singular["rules"] as $key => $value) {
            if(preg_match($key, $word)) {
                return preg_replace($key, $value, $word);
            }
        }

        // Well, right now the word couldn't be singularized
        // so return it as it was (or throw an exception?)
        return $word;
    }
public static function singular ( string $ word ) : string { // Check that `$word` is countable. if ( in_array ( $ word , Inflector :: $ _uncontable ) ) { return $ word ; } // Now check that `$word` is regular. if ( isset ( Inflector :: $ _singular [ "irregular" ] [ $ word ] ) ) { return Inflector :: $ _singular [ "irregular" ] [ $ word ] ; } // Now check that `$word` can be singularize. foreach ( Inflector :: $ _singular [ "uninflected" ] as $ rule ) { if ( preg_match ( "/^" . $ rule . "$/" , $ word ) ) { return $ word ; } } // Now the word follows a rule, so apply it foreach ( Inflector :: $ _singular [ "rules" ] as $ key => $ value ) { if ( preg_match ( $ key , $ word ) ) { return preg_replace ( $ key , $ value , $ word ) ; } } // Well, right now the word couldn't be singularized // so return it as it was (or throw an exception?) return $ word ; }
Returns the singular form of the word.

@param string $word Word to singularize.

@return string The singular form of `$word`.
Returns the singular form of the word .