【发布时间】:2011-02-23 11:59:34
【问题描述】:
我有一个会话变量$_SESSION["animals"],其中包含一个带有值的深层 json 对象:
$_SESSION["animals"]='{
"0":{"kind":"mammal","name":"Pussy the Cat","weight":"12kg","age":"5"},
"1":{"kind":"mammal","name":"Roxy the Dog","weight":"25kg","age":"8"},
"2":{"kind":"fish","name":"Piranha the Fish","weight":"1kg","age":"1"},
"3":{"kind":"bird","name":"Einstein the Parrot","weight":"0.5kg","age":"4"}
}';
例如,我想找到带有“Piranha the Fish”的行,然后将其删除(并按原样再次对其进行 json_encode)。
这个怎么做?我想我需要在 json_decode($_SESSION["animals"],true) 结果数组中搜索并找到要删除的父键,但我还是被卡住了。
【问题讨论】: