PHP array_shift equivalent in golang


We use reflect as the example:

package main

import (
	"fmt"
	"reflect"	 
)
 
func main() {
	hth:=map[string]string{"a":"1","b":"c"}
	n1 :=array_shift(hth)
	fmt.Println(n1)
	fmt.Println(hth)	 
}

func array_shift(abc interface{}) (interface{}){  
	key := reflect.ValueOf(abc).MapKeys()[0].String() 
	v := reflect.ValueOf(abc)	
	i := v.MapIndex(reflect.ValueOf(key))
	v.SetMapIndex(reflect.ValueOf(key),reflect.Value{})
	return i  
}

Result:

1
map[b:c]

Leave a Reply