loading...

How To Compare Two Strings In PHP If Condition?

pakainfocom profile image pakainfo ・1 min read

In this best example I am going to look at all the multiple ways you can compare strings in PHP using a number of built in PHP functions php compare strings.

== operator
strcmp Function
strcasecmp Function

== Operator

The most useful way you will getting output display like Your Strings match. or Your Strings do not match. of comparing two User data strings is simply by using the
PHP == operator if the two data strings are equal to each other then it returns boolean data like as true.

Using the == operator, Strings match is printed

if('user_data_string1' == 'user_data_string1')
{
    echo 'Good Luck, User Strings match.';
} else {
    echo 'Sorry, Your User Strings do not match.';
}

strcmp function, Strings match is printed

if(strcmp('user_data_string1', 'user_data_string1') == 0)
{
     echo 'Good Luck, Strings match.';
} else {
     echo 'Sorry, Your Strings do not match.';
}

php compare strings

Posted on by:

pakainfocom profile

pakainfo

@pakainfocom

My name is Angular King. I'm a full-stack developer, entrepreneur and owner of Pakainfo. I live in India and I love to write

Discussion

pic
Editor guide