Search code examples
phpstringstrcmp

Strcmp trouble. Strings are no equal


why its echo 1 ? this 2 strings are the same! strcmp() should be 0! What's wrong? Can someone tell me why this two strings are NOT equal?

if(!strcmp("+7 (921) 111-11-11", "+7 (921) 111-11-11"))
    echo "1";

Solution

  • strcmp() does evaluate to 0 in this case - But this leads to it being type juggled to false, and then to !false, so the original statement runs. Change it to this:

    if (strcmp("+7 (921) 111-11-11", "+7 (921) 111-11-11") !== 0) 
        echo 1; // Strings are not equal