NYCPHP Meetup

NYPHP.org

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

Kristina Anderson ka at kacomputerconsulting.com
Sun Aug 17 18:32:24 EDT 2008


Justin -- if you'd used a standard if/else block -- I wouldn't have 
learned something very important just now.

So I'm happy I asked.  Thanks fo the link!

-- Kristina

> 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.ter
nary
> 
> justin
> -- 
> http://justinhileman.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
> 
> 





More information about the talk mailing list