public static function insert($string, $substring, $index)
    {
        exception_if(!self::checkIndex($string, $index), StringOutIndexException::class);

        $str = '';

        for ($i = 0; $i < static::length($string); $i++) {
            if ($i == $index) {
                $str .= $substring;
            }

            $str .= $string[$i];
        }

        return $str;
    }
public static function insert($string, $substring, $index)
    {
        exception_if(!self::checkIndex($string, $index), StringOutIndexException::class);

        $str = '';

        for ($i = 0; $i < static::length($string); $i++) {
            if ($i == $index) {
                $str .= $substring;
            }

            $str .= $string[$i];
        }

        return $str;
    }
public static function insert ( $ string , $ substring , $ index ) { exception_if ( ! self :: checkIndex ( $ string , $ index ) , StringOutIndexException :: class ) ; $ str = '' ; for ( $ i = 0 ; $ i < static :: length ( $ string ) ; $ i ++ ) { if ( $ i == $ index ) { $ str .= $ substring ; } $ str .= $ string [ $ i ] ; } return $ str ; }
Insert a substring inside another string.

@param string $string
@param string $substring

@return string
Insert a substring inside another string .