PHP strncmp Function

What is strncmp Function?


In PHP this function is used for binary safe string comparison of the first n characters.



In the above syntax "string1" ,"string2" are the strings to compare, "length" specifies the number of character for each string to be used in the comparison.The function returns "0" if both strings are equal, returns a value "<0" if string1 is less than string2, returns a value ">0" if string1 is greater than string2.

Example :

echo strncmp("Hello world!","Hello india!",6);
Result :


In the above example both the string are equal, so the strncmp() returns "0".

PHP Topics

Ask Questions

Ask Question