PHP strcmp() string function

PHP strcmp() function

The PHP strcmp() string function used to compare two strings. If both string are same then returns zero(0), if does not same returns any other digit value except zero(0) depend on length of both string.

The PHP strcmp() function syntax

strcmp(“string1″, “string2″);

Here, we have two strings string1 and string2 if both are same then return zero(0).

The strcmp() function works like :

returns 0 if both strings are equal

returns >0 if string1 is greater than string2

returns <0 if string2 is greater than string1

PHP strcmp() string function example

The out put is:
The string compare =  0, as both strings are equal.

 

The string compare = -1 , here both string are same but there is a different in letter case so  the result is -1.

 

The string compare = 8, because the string1 is greater than string2.

strcmp() function php form example

Now lets take an example of php form for understand strcmp() string function. create a php web form with two textboxes for input two values and a submit button control for compare entered two strings are same or not using strcmp() function.

The output of above php strcmp() function is:

PHP strcmp() string function example

PHP strcmp() string function example

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 5 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">