Dave's Brain

Browse - Programming Tips - How do I delete an element from a PHP array?

Date: 2007nov19
Language: php

Q.  How do I delete an element from a PHP array?

A.  You can unset($a[$element]) but that leaves a hole so the only way is
to copy the array to a new one without the unwanted element.

I think this is an unfortunate limitation for a high level language.
Even C++'s vector can erase() elements.

The only exceptions are:

array_shift() Remove the first array element array_pop() Remove the last array element

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.