On 3/8/08, Hans Zaunere <[EMAIL PROTECTED]> wrote: > > Is there any preference for: > > > > $val = isset($arr['key']) ? $arr['key'] : null; > > > This is preferred - it's actually doing something correct. > > > vs: > > > > $val = @$arr['key']; > > This is a hack, which causes an error, which you're then suppressing > > Marcus and I discussed a shortcut for the first example at the last Montreal > PHP Conference, but I don't think it's been implemented yet.
Actually I've been using the following function a lot too: function _array_val($a, $k, $d = null) { if (array_key_exists($k, $a)) return $a[$k]; if (func_num_args() == 3) return $d; throw new Exception("No such array key: $k"); } --8<-- example --8<-- $val = _array_val($arr, 'key', false); Of course it's a little slower but it makes for clean code. Mike -- Michael B Allen PHP Active Directory SPNEGO SSO http://www.ioplex.com/ _______________________________________________ New York PHP Community Talk Mailing List http://lists.nyphp.org/mailman/listinfo/talk NYPHPCon 2006 Presentations Online http://www.nyphpcon.com Show Your Participation in New York PHP http://www.nyphp.org/show_participation.php