嗯?foreach 本来不就是喷阵列 / 物件的吗? ._.
你的 string decode 后应该结构是这样
$json:
test:
0:
pid: 34
name: cat
1:
pid: 35
name: dog
用 foreach 下去转 $json(as $k => $v)
$k = test
$v = [
0:
pid: 34
name: cat
1:
pid: 35
name: dog
]
如果你要继续拿到 pid,要用 foreach 转每个 $v(as $sk => $sv),
这样才会是
$sk = 0
$sv = [
pid: 34
name: cat
]
$sk = 1
$sv = [
pid: 35
name: dog
]
总之你需要多一层循环 :Q