public static function toSnakeCase(
        string $str,
        bool $uppercase = false
    ): string
    {
        $str = trim($str);
        $str = preg_replace("~[^a-z0-9]+~i", "_", $str);

        /**
         * @param array<string> $arg
         *  [0] the match
         *  [1] the character
         */
        $fn = function($arg) {
            $match = $arg[0];
            return $match[0]."_".$match[1];
        };
        $ret = preg_replace_callback("~([a-z])[A-Z]~", $fn, $str);
        return ($uppercase) ? strtoupper($ret) : strtolower($ret);
    }
public static function toSnakeCase(
        string $str,
        bool $uppercase = false
    ): string
    {
        $str = trim($str);
        $str = preg_replace("~[^a-z0-9]+~i", "_", $str);

        /**
         * @param array<string> $arg
         *  [0] the match
         *  [1] the character
         */
        $fn = function($arg) {
            $match = $arg[0];
            return $match[0]."_".$match[1];
        };
        $ret = preg_replace_callback("~([a-z])[A-Z]~", $fn, $str);
        return ($uppercase) ? strtoupper($ret) : strtolower($ret);
    }
public static function toSnakeCase ( string $ str , bool $ uppercase = false ) : string { $ str = trim ( $ str ) ; $ str = preg_replace ( "~[^a-z0-9]+~i" , "_" , $ str ) ; /**
         * @param array<string> $arg
         *  [0] the match
         *  [1] the character
         */ $ fn = function ( $ arg ) { $ match = $ arg [ 0 ] ; return $ match [ 0 ] . "_" . $ match [ 1 ] ; } ; $ ret = preg_replace_callback ( "~([a-z])[A-Z]~" , $ fn , $ str ) ; return ( $ uppercase ) ? strtoupper ( $ ret ) : strtolower ( $ ret ) ; }
Convert a string to snake_case

@param string $str
@param bool $uppercase
@return string
Convert a string to snake_case