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'.
()
| 240 | // string keys. Non-array values are implicitly converted to single-element maps |
| 241 | // with a key of '0'. |
| 242 | func (v *Value) Map() map[string]interface{} { |
| 243 | val := make(map[string]interface{}) |
| 244 | keys := &Value{value: C.value_array_keys(v.value)} |
| 245 | |
| 246 | for _, k := range keys.Slice() { |
| 247 | switch key := k.(type) { |
| 248 | case int64: |
| 249 | t := &Value{value: C.value_array_index_get(v.value, C.ulong(key))} |
| 250 | sk := strconv.Itoa((int)(key)) |
| 251 | |
| 252 | val[sk] = t.Interface() |
| 253 | t.Destroy() |
| 254 | case string: |
| 255 | str := C.CString(key) |
| 256 | t := &Value{value: C.value_array_key_get(v.value, str)} |
| 257 | C.free(unsafe.Pointer(str)) |
| 258 | |
| 259 | val[key] = t.Interface() |
| 260 | t.Destroy() |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | keys.Destroy() |
| 265 | return val |
| 266 | } |
| 267 | |
| 268 | // Ptr returns a pointer to the internal PHP value, and is mostly used for |
| 269 | // passing to C functions. |