Forums

PHP / WordPress logic help (&&, ||, etc) (4 posts)

  1. clarke1866
    Member
    Posted 6 years ago #

    I'm working on a plugin for WP but I am running into a PHP logic problem. Given $Var_check equals "1" and my_function does exist , what is wrong with my logical PHP statement below. It always echo's 'Always get this...' when it should actually return 'I should get this but...'

    // Check to see if options are logical
    if ( ($Var_check == "1") || ($Var_check == "6") && (function_exists('my_function'))) {
    echo "I should get this, but...";
    } else {
    echo 'Always get this...'}

    Is it my syntax? Any help would be very much appreciated.

  2. Les Bessant
    Moderator
    Posted 6 years ago #

    I'm not much of a coder, but what I think is happening is that you're checking for:

    Does $Var_check =1? OR Does $Var_check =1 AND is there a function called My_function?

    Try this:

    EDIT: mangled code, posting again

  3. Les Bessant
    Moderator
    Posted 6 years ago #

    Or this:

    <?php // Check to see if options are logical

    function my_function() {
    echo 'Hi';
    }
    $Var_check =1;
    if ( (($Var_check == "1") || ($Var_check == "6")) && (function_exists('my_function'))) {
    echo "I should get this, but...";
    } else {
    echo 'Always get this...';}
    ?>

  4. clarke1866
    Member
    Posted 6 years ago #

    Thanks for the reply. I had your version earlier and it didn't work. Sad. But I very much appreciate your response. I got frustrated and decided to take the query in another direction. Probably not as elegant, but it gets the job done.

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags