[nycphp-talk] empty($array['foo']) versus array_key_exists('foo', $array)
Paul A Houle
paul at devonianfarm.com
Mon Oct 25 13:32:38 EDT 2010
On 10/25/2010 1:12 PM, Rob Marscher wrote:
> On Oct 25, 2010, at 1:03 PM, Paul A Houle wrote:
>> On 10/25/2010 12:22 PM, David Mintz wrote:
>>> Anybody know of any reason not to save a little typing with
>>> empty($array['foo'])
>> I think also this will throw an error or exception if you're running with E_STRICT, which you should.
> I thought so too, but I tested it this morning and it didn't seem to throw a notice. It must operate like isset.
>
Well if you think array_key_exists($key,$array) is wack, you can write
function has_key($array,$key) {
return array_key_exists($key,$array);
}
personally I hate the reversal of order in array_key_exists as
compared to $array[$key]. The only trouble is that this one more thing
for the guy who maintains your code in the future to remember.
More information about the talk
mailing list