I prefer to develop with E_NOTICES turned on, but I often have to write excess, overly verbose, code when working with array indexes. How can I write this code in less code with E_NOTICES enabled.
With notices suppressed
if ($_REQUEST['some_key'] == 'bob')
{
}
Without notices suppressed
if (array_key_exists('some_key', $_REQUEST) && $_REQUEST['some_key'] == 'bob')
{
}
I generally use
isset(), instead ofarray_key_exists(), for that kind of thing ; which means using something like this :A couple of differences :
issetis a language construct, and not a function -- and its faster (no function call)issetwill returnfalseif a data isnull;array_key_existswill returntrueif (isset($_REQUEST['a'], $_REQUEST['b'], $_REQUEST['c']), if necessary