NYCPHP Meetup

NYPHP.org

[nycphp-talk] Accessing non-existent array elements ok?

justin justin at justinhileman.info
Sun Aug 17 18:25:37 EDT 2008


On Sun, Aug 17, 2008 at 6:10 PM, Kristina Anderson
<ka at kacomputerconsulting.com> wrote:
> Hi all.  I have a question regarding the below syntax
>
> $result = isset($a['c']) ? $a['c'] : NULL;
>
>
> This is testing two conditions, first if $a['c'] is set, and then, if $a
> ['c'] is NULL...correct?
>
> What would $result be if $a['c'] is set but is not NULL?  The same as
> if $a['c'] was not set?  or...?
>
> I've seen similar syntax before, in some code Tedd & I were working
> with a couple of months back...and just want to make sure I fully
> understand what is actually happening with it.
>

Kristina,

Sorry, I probably should have used a standard if/then block... That
shorthand is called a ternary operator, or a ternary comparison. See:

http://us.php.net/operators/comparison#language.operators.comparison.ternary

justin
-- 
http://justinhileman.com



More information about the talk mailing list