Fetching an array value and removing it So I have this array:

$arr = ('a' =&gt; 343, 'b' =&gt; 34, 'c' =&gt; 65, 'd' =&gt; 465);


which could also be

$arr = ('a' =&gt; 343, 'b' =&gt; 34, 'c' =&gt; 65);


Can the following code be improved into one line?

if(isset($arr['d'])) $something = $arr['d'];
unset($arr['d']);
if(isset($arr['d'])) $something = $arr['d'];
unset($arr['d']);


Well... If arr['d'] is not set, then you don't need to unset it. So this will save an unnecessary call sometimes:

if(isset($arr['d']))
{
    $something = $arr['d'];
    unset($arr['d']);
}


If you don't care for $something, then you can just do

unset($arr['d']);


Which is then one line. You could also write

if (isset($arr['d']) &amp;&amp; ($something = $arr['d']) !== null) unset($ar['d']);


That is one line as well, but will fail to do what you like if $something is null. And from the point of readability it's questionable whether this is an improvement.