PHP strncmp() Function (original) (raw)

Last Updated : 22 Jun, 2023

The strncmp() is an inbuilt function in PHP which is used to compare first n character of two strings. This function is case-sensitive which points that capital and small cases will be treated differently, during comparison. This function compares two strings with first n character and tells whether the first string is greater or smaller or equal to the second string.

int strncmp( str1,str1, str1,str2, $len )

Parameters: This function accepts three parameters as mentioned above and described below:

Return Value: This function returns a random integer value depending on the comparison of string which is given below:

Below programs illustrate the strncmp() function in PHP.

Program 1:

PHP `

`

Program 2:

PHP `

`

Related Articles:

Reference: http://php.net/manual/en/function.strncmp.php