Jump to content

Can someone explain the parentheses structure for negation operators


probsdorg

Recommended Posts

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.