Comparing two strings is one of the most commonly used string operation in programming and web development practices. The strcmp() is an inbuilt function in PHP and is used to compare 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 and tells us that whether the first string is greater or smaller than the second string or equals to the second string.
Parameters: This function accepts two parameters which are described below:
- $string1 (mandatory): This parameter refers to the first string to be used in the comparison
- $string2 (mandatory): This parameter refers to the second string to be used in the comparison.
Return Values: The function returns a random integer value depending on the condition of match, which is given by:
- Returns 0 if the strings are equal.
- Returns a negative value (<0), if $string2 is greater than $string1.
- Returns a positive value (>0) if $string1 is greater than $string2.
In this code we will try to understand the working of strcmp() function:
0 31 -31
- String comparison using == vs strcmp() in PHP
- D3.js | d3.lab() Function
- D3.js | d3.hcl() Function
- p5.js | box() Function
- CSS | hsl() Function
- PHP | ord() Function
- PHP | tan( ) Function
- PHP | Ds\Map xor() Function
- p5.js | nfc() function
- p5.js | nf() Function
- PHP | Ds\Map put() Function
- D3.js | d3.set.add() Function
- PHP | sin( ) 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.