Is there a way to do this in one line in PHP:
if(key_exists('abc', $data)) {
$newVar = $data['abc'];
unset($data['abc']);
}
Thanks!
Is there a way to do this in one line in PHP:
if(key_exists('abc', $data)) {
$newVar = $data['abc'];
unset($data['abc']);
}
Thanks!
No, but you could make a function for it:
function detach(array &$array, $key) {
if (!array_key_exists($key, $array)) {
return null;
}
$value = $array[$key];
unset($array[$key]);
return $value;
}
$newVar = detach($array, 'abc');