PHP strncmp Function

What is strncmp Function?

Explanation

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

Syntax:


strncmp(string1,string2,length)

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 :


<?php
echo strncmp("Hello world!","Hello india!",6);
?>
Result :

0

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

PHP Topics


Ask Questions

Ask Question