Go自身没有while循环的语法。相应的,Go使用 for 循环代替实现while循环.
// Gopackage mainimport "fmt"func main() { sum := 1 for sum < 100 { sum += sum } fmt.Println(sum)}// PHP$sum = 1;while ($sum < 100) { $sum += $sum;}echo $sum;Foreach/RangePHP使用 foreach 迭代数组和对象。与之对应, Go使用 range 迭代 slice 或 map。
// Gopackage mainimport "fmt"func main() { colours := []string{"Maroon", "Red", "Green", "Blue"} for index, colour := range colours { fmt.Printf("index: %d, colour: %s", index, colour) }}// PHP$colours = ["Maroon", "Red", "Green", "Blue"];foreach($colours as $index => $colour) { echo "index: {$index}, colour: {$colour}";}今天的内容就是这些。我尽量使文章篇幅较小且简洁。作为PHP开发人员, 我尝试在练习Go时分享我的知识。也请随意分享你的想法。希望你们喜欢阅读本篇文章。
做网站的话,php更好一些,最新版的php7对性能做了不小的优化,如果是应用层的话,go更好一点。