在PHP中从数组中分离元素

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');
if(isset($data['abc'))
{
    unset($data['abc']);
}

In one line:

if ($newVar = $data['abc'])  unset($data['abc']);