NYCPHP Meetup

NYPHP.org

[nycphp-talk] empty($array['foo']) versus array_key_exists('foo', $array)

David Mintz david at davidmintz.org
Mon Oct 25 12:32:18 EDT 2010


On Mon, Oct 25, 2010 at 12:25 PM, Dan Cech <dcech at phpwerx.net> 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'])
>>
>
> They're different comparisons, array_key_exists will return true if there
> is an element with that key *even if it is null or some other empty() value*
> (and the logic is reversed, you need !empty()), isset($array['foo']) is
> closer but will return false if the value is null.
>
> http://us3.php.net/manual/en/types.comparisons.php
>
>



Ah yes, of course. I might have added that for what I have in mind, if
$array['foo'] existed and were any empty() value, that would serve my
purposes just as well.  Here's a deep insight:  array_key_exists is nice for
finding out if the array key exists.

Thanks.


-- 
David Mintz
http://davidmintz.org/
It ain't over:
http://www.healthcare-now.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20101025/74167cc6/attachment.html>


More information about the talk mailing list