What is a good strategy for safely reading values out of a PHP array?
<p>I'm trying to read values from $_SESSION which may or may not be set, while avoiding undefined index warnings.  I'm used to Python dicts, which have a <code>d.get('key','default')</code> method, which returns a default parameter if not found.  I've resorted to this:</p>

<pre><code>function array_get($a, $key, $default=NULL)
{
  if (isset($a) and isset($a[$key]))
    return $a[$key];
  else
    return $default;
}

$foo = array_get($_SESSION, 'foo');
if (!$foo) {
  // Do some foo initialization
}
</code></pre>

<p>Is there a better way to implement this strategy?</p>
