What's the syntax for nested conditional statements?

95 views Asked by At

I want to check if $AD = 1, then if not pass to another function, but if $AD = 1 check if AC = contains some value, if not do some stuff.

if ($AD == '1'){
if ($AC == ''){
echo 'AC is empty';
} else { 
///////Function/////
}
}

Thanks.

2

There are 2 answers

2
ComFreek On BEST ANSWER

An else if statement must always correspond to a beginning if statement on the same "nesting level".

Your inner else if does not have any beginning if statement and it therefore fails.

if ($AD == 1) {
  if ($AC == '') {
    echo 'empty';
  }
}
else {
  otherFunction($AD);
}

Since this is basic PHP (actually IFs are mostly not language-dependent) stuff, I recommend you reading a beginner's tutorial.

2
Rob On
if ($AD == 1){
  if ($AC == ''){
    // some code where ac has the value
   } else {
     // some code where ac doesn't have the value
   }
 } else  {
   // other function
 }

That should do it