Remove element from an array.
Posted on 2007-03-28
Cannot see the wood for the trees, so this is going to be some EASY points!
I have a dynamic array; i.e. at RUNTIME, values are added and removed.
Well, added is OK.
$a_Array = 'value';
By using in_array() I know if the value is already in the array.
How do I remove the value from the array? I have a stupidly convoluted way...
Get the key of the value and then unset that element.
$a = array('one','two',4 => 'three', 3 => 'four'); // NOT a typo!!!!
unset($a[reset(array_keys($a, 'three', True))]);
This is OK, the output is ...
0 => 'one',
1 => 'two',
3 => 'four',
Strict Standards: Only variables should be passed by reference on line 3
So, I suspect there is really a array_remove(&$array, $value) function SOMEWHERE.