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, $str2, $len )
Parameters: This function accepts three parameters as mentioned above and described below:
- $str1: It is mandatory parameter. This parameter refers to the first string to be used in the comparison.
- $str2: It is mandatory parameter. This parameter refers to the second string to be used in the comparison.
- $len: It is mandatory parameter which is used to define the first $len number of characters compared.
Return Value: This function returns a random integer value depending on the comparison of string which is given below:
- Returns 0 if the first n character of both strings are equal.
- Returns a negative value ( < 0), if the first n character of $string2 is greater than $string1.
- Returns a positive value ( > 0), if the first n character of $string1 is greater than $string2.
Below programs illustrate the strncmp() function in PHP.
0 31 -3
- p5.js | max() function
- p5.js | int() function
- PHP | Ds\Map last() Function
- PHP | Ds\Map map() Function
- PHP | dir() Function
- PHP | abs( ) Function
- p5.js | hue() function
- p5.js | min() function
- PHP | max( ) Function
- p5.js | cos() function
- p5.js | sin() function
- p5.js | log() function
- PHP | min( ) Function
- p5.js | red() function
- p5.js | tan() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.