Variable
GO |
PHP |
var variable string = "Hello" |
$variable="Hello" |
var variable int = 5 |
$variable=5; |
var variable bool = true |
$variable=true; |
var variable float64 = 1.2 |
$variable=1.2; |
var variable interface{} = "Hi" |
$variable="Hi"; |
const AKM int = 5 |
define("AKM",5); |
const AKM int = 5 |
const AKM=5; |
Example 1
package main
import "fmt"
var c int=5
func main() {
var a string="Hello"
b:="World"
fmt.Printf("%s %s => %d",a,b,c)
fmt.Printf("\n")
d := a + " " + b
fmt.Println(d)
}
<?php
$c=5;
$a=(string)"Hellow";
$b="World";
printf("%s %s => %d",$a,$b,$c);
echo "\n";
$d=$a." ".$b;
echo $d;
Map
package main
import "fmt"
func main() {
variable := make(map[string]int)
variable["a"] = 1
variable["b"] = 2
variable["c"] = 3
fmt.Printf("%v", variable)
fmt.Println("\n")
variable2 := map[string]int{"a": 1, "b": 2, "c": 3}
fmt.Printf("%v", variable2)
}
<?php
$variable=array();
$variable["a"]=1;
$variable["b"]=2;
$variable["c"]=3;
var_dump($variable);
echo "\n";
$variable2=array(
"a"=>1,
"b"=>2,
"c"=>3,
);
var_dump($variable2);