jimfog Posted January 5, 2012 Share Posted January 5, 2012 Look at the following code: if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); According to the author if the month is not "requested"(not passed to the request superglobal array by a user input) it will default to date("n")-the "request" array. My q is the following, since this is an if statement shouldn't this piece of code: $_REQUEST["month"] = date("n"); be enclosed in brackets{}? Thanks. Link to comment Share on other sites More sharing options...
thescientist Posted January 5, 2012 Share Posted January 5, 2012 it doesn't need curly braces because it is only one statement. if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if you added a second statement then you would get an error and would need to enlose them all with the curly braces. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 5, 2012 Share Posted January 5, 2012 It wouldn't be an error, it would only include the first line in the if statement and the second line would always be executed. If you have any control structure, like a loop, conditional, etc, and the body contains multiple lines then you need the brackets. If you leave out the brackets then it assumes that the body only contains one line. Link to comment Share on other sites More sharing options...
jimfog Posted January 5, 2012 Author Share Posted January 5, 2012 Thanks for the valuable info-i really did not know that. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.