Array (
[REF_DETAILS] = Array
(
[0] = Array
(
[ID] => 1231312
[USER] => USER
)
[1] = Array
(
[TID] => 2754042
[USER] = USER
)
[1] = Array
(
[TID] => 534535
[USER] = USER
)
)
[TOTAL_COUNT] = 31
)
我有一个像上面这样的数组输出,我想从数组中删除一个元素然后再次我想从0重新索引它。我尝试在php中使用array_value但是在执行此操作后它将删除[REF_DETAIL] 0和TOTAL_COUNT为1,请在php中提供解决方案
答案 0 :(得分:5)
使用array_splice
(php docs),它会自动重新编制索引。
array_splice($array['REF_DETAILS'], 1, 1)
答案 1 :(得分:4)
尝试
unset($array['REF_DETAILS'][1]);
$array['REF_DETAILS'] = array_values($array['REF_DETAILS']);
答案 2 :(得分:1)
$arr = Array (
'REF_DETAILS' => Array(
0 => Array(
'ID' => '> 1231312',
'USER' => '> USER',
),
1 => Array(
'TID' => '> 2754042 ',
'USER' => 'USER',
),
2 => Array(
'TID' => '> 534535 ',
'USER' => 'USER',
),
),
'TOTAL_COUNT' => 31,
);
array_shift($arr['REF_DETAILS']);
print_r($arr);
<强>输出:强>
Array
(
[REF_DETAILS] => Array
(
[0] => Array
(
[TID] => > 2754042
[USER] => USER
)
[1] => Array
(
[TID] => > 534535
[USER] => USER
)
)
[TOTAL_COUNT] => 31
)