Archive for March, 2009

Deleting array element by key in PHP

March 26th, 2009

I had to think about this one for a while, as I was trying to delete an array element which I knew the key of (and there is no array_delete() function).

1
e.g. $array['something'] = 'value';

Turns out deleting the value is easy using the unset() command.

1
unset($array['something']);

$array['something'] no longer exists. Hope this helps someone else.