probsdorg Posted October 8, 2010 Share Posted October 8, 2010 Can someone help me understand parentheses structure? Why here does the second empty() have no parentheses before it and an extra parentheses at the end? if (empty($subject) && empty($text)) { .... And here, why is there an extra parentheses at the end? if (empty($subject) && (!empty($text))) { ... And here, why double parentheses in the 1st empty() and none before the 2nd empty() ? if ((!empty($subject)) && empty($text)) { ... Thank You! michael Quote Link to comment https://forums.phpfreaks.com/topic/215459-can-someone-explain-the-parentheses-structure-for-negation-operators/ Share on other sites More sharing options...
BlueSkyIS Posted October 8, 2010 Share Posted October 8, 2010 there must always be the same number of left parentheses as right parentheses. the far left and far right parentheses define the entire if statement. similarly, pairs of left/right parentheses can define sub-statements within the larger statement. also, a function called with a parameter must use () to pass that parameter. it might help you to understand if you either add more spaces between paren's and/or break them onto lines: if ( empty($subject) && empty($text)) { // if $subject and $text are both emptyif ( empty($subject) && (!empty($text))) { // If $subject is empty and $text is not empty.// This is exactly the same without the extra paren's:if ( empty($subject) && !empty($text)) { // If $subject is empty and $text is not empty. Quote Link to comment https://forums.phpfreaks.com/topic/215459-can-someone-explain-the-parentheses-structure-for-negation-operators/#findComment-1120401 Share on other sites More sharing options...
KevinM1 Posted October 8, 2010 Share Posted October 8, 2010 Moreover, parentheses enforce associativity. If the order of operations of an expression aren't known, extra parentheses can be used to explicitly enforce a particular ordering. http://www.php.net/manual/en/language.operators.precedence.php Quote Link to comment https://forums.phpfreaks.com/topic/215459-can-someone-explain-the-parentheses-structure-for-negation-operators/#findComment-1120410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.