PHP NOT EQUAL

Jim,
I’m working on some PHP code to try to do what I was saying, but I really don’t know much PHP.

If this PHP code

if ($answer == "water")

means: if $answer = water, then how do you write if $answer doesn’t = water?

Thanks Jim,

Roger

Comments

  1. AMPC says:

    Hi Roger,

    In PHP a single equal sign is an assignment operator and used to assign a value to a variable. Two equal signs are a comparison operator, that is, it’s used to compare two values. So, in this case, we use two equal signs to compare the two items: $answer and ‘water’

    <?
    $answer = "water";
    if($answer == "water")
    echo "Water!";
    else
    echo "You need water!"
    ?>

    or

    <?
    if($answer != "water")
    echo "You need water!";
    ?>

    Hope that helps

Speak Your Mind

Comment moderation is enabled. Your comment may take some time to appear.