Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

What does this mean in PHP?

if(isset($events[$event_day])

I know it is checking if it is set but what exactly is $events[$event_day]? Is it an array and a key?

3 Answers

It seems to be, You can always do a var_dump($events[$event_day]); then you'll see the datatype printed to the screen along with other info.

I did the var_dump and it returned about 30 results of NULL so it must be an array. Thanks.

isset is a boolean function (produces either True or False response) that determines if a variable has been set or not. If the events variable has a value set to it, it will execute the code in the curly brackets following. You would normally use it in conjunction with an IF/ELSE statement like...

if(isset($events[$event_day]) {
          echo " 'events' array has 'event_day' value set to it";
} else {
          echo " 'events' array doesn't have an  'event_day' value set to it";
}

I'm still a newbie and pretty sure this isn't the best way to describe it, but here is a pretty good non-technical explanation (http://kunststube.net/isset/).

Haha, oops should have actually read your question.