Tag: code

  • if problems

    This is definitely one for the geek files, so if multi-condition PHP if statements mean nothing to you, feel free to move along.  I won’t be offended.

    Ok, just geeks left?  Good, here we go.

    Last night I was trying to correct a syntax error and came across a helpful way to determine if all the parentheses in my if statement matched each other.  Basically how it works is like this.  Start counting each parenthesis in your statement. Each time you see an open parenthesis you increase your count by 1 and each time you see a close parenthesis you decrease your count by 1.  Let me illustrate:

    // 12                 1    23   4           3      2    3      4                3210
    if (($condition1 != $a) || ((len($condition2) == $b) && (!isset($_POST['submit'])))) {

    Don’t know if that helps you or not, but as the editor i was using (online) didn’t have a syntax checker, it helped me a great deal.