Please can you help me understand how generating a slice from an array works. Why are ID1 and ID2 not the same?
a := [2]string{"a", "b"}
b := [2]string{"c", "d"}
var z [2][2]string
z[0] = a
z[1] = b
fmt.Printf("%s\n", z)
var id [][]string
for _, t := range z {
temp := t[:]
id = append(id, temp)
}
fmt.Printf("\nid1 = %s", id)
var id2 [][]string
for _, t := range z {
temp := t
id2 = append(id2, temp[:])
}
fmt.Printf("\nid2 = %s", id2)
[[a b] [c d]]
id1 = [[c d] [c d]]
id2 = [[a b] [c d]]