Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ivan Tomicic
3,873 PointsWhat if there is no variable in page?
Ok I tried to work on this task and if I don't set any variable to index.php browser gives me an error, how can I tell it just not to show anything in code if there is no variable? I tried with else function but no luck?
1 Answer

miguelcastro2
Courses Plus Student 6,573 Points// Check to see if a variable is set
if (isset($my_variable)) {
echo 'Set';
} else {
echo 'Not Set';
}
Ivan Tomicic
3,873 PointsIvan Tomicic
3,873 PointsOk, but I need to check for variable too, is there a shorter way than this
miguelcastro2
Courses Plus Student 6,573 Pointsmiguelcastro2
Courses Plus Student 6,573 PointsIn this IF clause, if the first condition is TRUE, meaning that the variable $section is set, then it will check the second condition to see if $section == "shirts".
Ivan Tomicic
3,873 PointsIvan Tomicic
3,873 PointsThank you!
Jason Anello
Courses Plus Student 94,597 PointsJason Anello
Courses Plus Student 94,597 PointsHi Ivan,
This was the code I used if you want to compare to your own:
There's no need to have the else block where you echo out an empty string.
Ivan Tomicic
3,873 PointsIvan Tomicic
3,873 PointsOh, thank you, that is useful :)