PHP To Go 转型手记 (一)

PHP To Go 转型手记 (一)

前言

作为一名PHP程序员,我感到荣幸。但在时代不断的变迁中,要具备足够的知识才可生存。

那就从Go语言学起把。

希望看到本篇文章的你可以对Go有一个基本的认识。本系列文章与我自己学习Go语言的方式去描述。以PHP代码与Go代码的对比加以区分理解。

变量

PHP

// 初始化变量
$domain = "blog.fastrun.cn";
// 批量赋值
$domain = $domain1 = $domain2 = "blog.fastrun.cn";

Go

// 初始化变量
var domain string = "blog.fastrun.cn"
// 批量赋值
var domain,domain1,domain2 string = "blog.fastrun.cn"
// 批量声明赋值
var username,age,local = "zhangsan",13,"BeiJing"
var(
    username="zhangsan"
    age = 13
    local = "BeiJing"
)

常量

PHP

define("FOO","something");

Go

// 单独声明
const FOO [string]= something
// 批量声明
const (
    USERNAME = "zhangsan"
    AGE      = 30
)

打印

PHP

// 基本输出
echo "blog.fastrun.cn";
// 格式化输出
printf("my blog %s","blog.fastrun.cn");

Go

// 基本输出
fmt.Println("blog.fastrun.cn")
// 格式化输出
fmt.Printf("my blog %s","blog.fastrun.cn")

函数

PHP

// 基本声明
function printString(string $string){
    echo $string;
}
// 带返回值
function printString(string $string) : string{
    return $string;
}

Go

// 基本声明
func printString(s string){
    fmt.Println(s)
}
// 带返回值
func printString(s string) string{
    return s
}

致谢

感谢你看到这里,希望本篇文章可以帮到你。谢谢

原创文章,作者:CrazyCodes,如若转载,请注明出处:https://blog.fastrun.cn/2018/10/27/1-71/

(0)
上一篇 2018年10月25日 下午8:28
下一篇 2018年10月28日 下午8:36

相关推荐

Remco Melis进行回复

您的电子邮箱地址不会被公开。 必填项已用*标注

评论列表(25条)

  • cennik
    cennik 2018年11月11日 下午3:55

    Awesome things here. I am very satisfied to see your post.
    Thanks a lot and I’m looking ahead to touch you. Will you kindly drop me
    a mail?

  • Micah
    Micah 2018年11月16日 上午6:54

    hello there and thank you for your info – I’ve definitely picked up something new
    from right here. I did however expertise a few technical points using
    this site, since I experienced to reload the web site lots of times previous to I
    could get it to load correctly. I had been wondering if your web host is OK?
    Not that I am complaining, but sluggish loading instances
    times will often affect your placement in google and could damage your
    quality score if advertising and marketing with Adwords.
    Anyway I am adding this RSS to my email and could look out for much
    more of your respective interesting content. Ensure that you update this
    again very soon.

  • pieczatki
    pieczatki 2018年11月27日 下午1:21

    Have you ever considered creating an ebook or guest authoring on other
    sites? I have a blog based on the same subjects you discuss and would love to have
    you share some stories/information. I know my subscribers
    would enjoy your work. If you’re even remotely interested, feel free to send
    me an email.

  • trần thạch cao
    trần thạch cao 2018年12月2日 上午6:09

    Everyone loves what you guys are usually up too. This
    kind of clever work and coverage! Keep up the good works
    guys I’ve incorporated you guys to my blogroll.

  • Remco Melis
    Remco Melis 2018年12月7日 上午9:16

    Everyone loves it when folks come together and share opinions.

    Great website, continue the good work!

  • naprawa stron,
    naprawa stron, 2018年12月11日 下午4:03

    Please let me know if you’re looking for a writer
    for your blog. You have some really good posts and I feel I would be a good asset.
    If you ever want to take some of the load off, I’d love to write some material for your blog in exchange for a link back to
    mine. Please shoot me an e-mail if interested. Thank you!

  • weselne
    weselne 2018年12月11日 下午5:22

    Thanks for some other excellent article. Where else may anybody get that kind of information in such
    an ideal means of writing? I have a presentation next week,
    and I’m on the search for such info.

  • AGEN JUDI
    AGEN JUDI 2018年12月12日 下午6:54

    Hey there! I just wanted to ask if you ever have any issues with
    hackers? My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no back up.
    Do you have any methods to prevent hackers?

    • crazycodes
      CrazyCodes 2018年12月13日 下午6:34

      @AGEN JUDIIf you don’t have a backup and the server doesn’t have a snapshot, it’s hard to get it back. I’m sorry

  • www.kreditrechner-portal.at
    www.kreditrechner-portal.at 2018年12月14日 上午1:12

    Hmm it appears like your website ate my first comment (it was super long) so I guess I’ll
    just sum it up what I had written and say, I’m thoroughly enjoying your blog.
    I too am an aspiring blog blogger but I’m still new to everything.

    Do you have any recommendations for novice blog writers? I’d certainly appreciate
    it.

  • agen sv388
    agen sv388 2018年12月17日 上午8:28

    Every weekend i used to go to see this site, as i want enjoyment, for the reason that
    this this web site conations in fact fastidious funny material too.

  • download
    download 2018年12月24日 上午12:43

    Wonderful website. A lot of helpful info here. I’m sending
    it to some buddies ans additionally sharing in delicious.
    And obviously, thanks for your sweat!

  • online dating
    online dating 2018年12月25日 上午6:31

    I truly love your site.. Very nice colors & theme. Did you create this web site yourself?
    Please reply back as I’m attempting to create my
    own personal site and would like to find out where you got this from or what the theme is named.
    Thank you!

  • Remco Melis
    Remco Melis 2018年12月25日 上午10:53

    I do consider all of the ideas you have offered
    in your post. They’re really convincing and will certainly work.

    Nonetheless, the posts are too brief for beginners. May just you please extend them a bit from subsequent time?
    Thanks for the post.

  • Remco Melis
    Remco Melis 2018年12月27日 下午3:10

    Thanks for ones marvelous posting! I definitely enjoyed reading
    it, you can be a great author.I will be sure to
    bookmark your blog and may come back later in life.

    I want to encourage you to ultimately continue your great writing, have a nice morning!

  • iphone 7 case kate spade
    iphone 7 case kate spade 2018年12月28日 上午12:56

    I think the admin of this site is in fact working hard in favor of his
    website, since here every information is quality based information.

  • agen online
    agen online 2018年12月29日 下午9:31

    Hey there! Do you use Twitter? I’d like to follow you if that would
    be okay. I’m absolutely enjoying your blog and look forward to new updates.

  • agen poker
    agen poker 2018年12月29日 下午9:34

    Thank you for sharing your thoughts. I truly appreciate your efforts and I am
    waiting for your next post thank you once again.

  • http://www.topadidas.fr
    http://www.topadidas.fr 2018年12月30日 下午10:22

    This piece of writing will help the internet people for creating
    new weblog or even a blog from startt too end.

  • 匿名
    匿名 2018年12月31日 下午6:49

    I enjoy reading a post that can make men and women think.

    Also, thank you for allowing me to comment!

  • michael kors rhea backpack
    michael kors rhea backpack 2019年1月2日 上午11:27

    I like the helpful info you provide in your articles.
    I will bookmark your weblog and check again here frequently.
    I am quite certain I will learn many new stuff right here!
    Good luck for the next!