Exemple #1
0
// Map returns the internal PHP value as a map of interface types, indexed by
// string keys. Non-array values are implicitly converted to single-element maps
// with a key of '0'.
func (v *Value) Map() map[string]interface{} {
	val := make(map[string]interface{})
	keys := &Value{value: C.value_array_keys(v.value)}

	for _, k := range keys.Slice() {
		switch key := k.(type) {
		case int64:
			t := &Value{value: C.value_array_index_get(v.value, C.ulong(key))}
			sk := strconv.Itoa((int)(key))

			val[sk] = t.Interface()
			t.Destroy()
		case string:
			str := C.CString(key)
			t := &Value{value: C.value_array_key_get(v.value, str)}
			C.free(unsafe.Pointer(str))

			val[key] = t.Interface()
			t.Destroy()
		}
	}

	keys.Destroy()
	return val
}
Exemple #2
0
// Slice returns the internal PHP value as a slice of interface types. Non-array
// values are implicitly converted to single-element slices.
func (v *Value) Slice() []interface{} {
	size := (int)(C.value_array_size(v.value))
	val := make([]interface{}, size)

	for i := 0; i < size; i++ {
		t := &Value{value: C.value_array_index_get(v.value, C.ulong(i))}

		val[i] = t.Interface()
		t.Destroy()
	}

	return val
}