我只是想删除所有“可见”设置为“0”的数组对象
大批:
{
"Count":5,
"0":{"id":"1","visible":"0"},
"1":{"id":"3","visible":"0"},
"2":{"id":"1","visible":"0"},
"3":{"id":"2","visible":"0"},
"4":{"id":"3","visible":"0"}
}
PHP:
function cleanup($arr) {
for($i = 0; $i < (count($arr)-1); $i++) {
if($arr[$i]['visible'] == false) {
unset($arr[$i]);
}
}
$newarr = array_unique($arr, SORT_REGULAR);
$newarr['Count'] = count($newarr)-1;
return $newarr;
}
结果:
{
"Count":2,
"3":{"id":"2","visible":"0"},
"4":{"id":"3","visible":"0"}
}
在我看来,这应该有效并返回 {"Count":0}。另外为什么没有将“键”设置为 0,1 而不是 3,4。我哪里错了?