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);
精彩评论