mirror of
https://github.com/php-win-ext/phpy.git
synced 2026-03-24 17:02:15 +01:00
699 B
699 B
数组操作
phpy.Array 是一个混杂类型,可能是 List 也可能是一个 Map。
创建
# List
l = phpy.Array([1, 3, 5, 2023, 7, 9])
# Map
m = phpy.Array({"hello": "world", "php": "swoole"})
读取
print(l[3])
print(m["php"])
长度
print(len(l))
print(len(m))
写入
# 设置 Key Value
m["swoole"] = 'coroutine'
# 追加元素到末尾
l.append(9999)
其他方法
get(key)读取set(key, value)写入unset(key)删除append(value)追加元素到列表末尾count()读取元素collect()转为Python原生的dict或listis_list()检测数组是否为List