I want something that works like array_pop()
or array_shift()
, so it returns the removed element, but I'd like to specify by key which element to remove.
Example:
$arr = ['a' => 1, 'b' => 2, 'c' => 3];
$removed = array_remove($arr, 'b');
print_r($arr); // Outputs: Array(['a'] => 1, ['c'] => 3 )
print_r($removed); // Outputs: 2
Now I'am using
$arr = ['a' => 1, 'b' => 2, 'c' => 3];
$removed = $arr['b'];
unset($arr['b']);