开发者

How can I delete elements from a php array?

How can I delete all the elements from an array, except for开发者_运维问答 one in particular?


You can unset individual elements using the unset function:

unset($array['element']);

A quick way to do what you intend is to simply create a new array:

$new_array = array('element' => $old_array['element']);
unset($old_array);

Or use array_slice:

$new_array = array_slice($old_array, $offset, 1, true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜