Hello All, I have a quick question about php strcmp

The manual states the following
Returns < 0 if str1 is less than str2; > 0 if str1 is greater than str2, and 0 if they are equal.

Can I simply and safely use string compare like this


IF ( !strcmp ($str1, $str2 ) ){
    # DO WHAT EVER AND WHEN EVER both strings are exactly equal and strcmp = 0 or FALSE
}ELSE{
    # DO WHAT EVER AND WHEN EVER strcmp is LESS than zero or GREATER then zero or TRUE as it were
}


Thanks for any explainations

I'm not sure if a -1 or negative number in general evaluates out to TRUE or FALSE???

    Since the return value is an integer, not a boolean, it would be better to state it as it is:

    if ( strcmp ($str1, $str2 ) == 0 ) {
        # DO WHAT EVER AND WHEN EVER both strings are exactly equal and strcmp = 0 or FALSE
    } else {
        # DO WHAT EVER AND WHEN EVER strcmp is LESS than zero or GREATER then zero or TRUE as it were
    }

    It may be even simpler to just compare $str1 == $str2.

    I'm not sure if a -1 or negative number in general evaluates out to TRUE or FALSE???

    A zero value is false, a non-zero value is true. Read the PHP manual on booleans.

      Write a Reply...