How does function strcmp() works in php
For this moment I do not understand in which cases I can use function strcmp() and how it actually works. Here we have several cases with different ways how this function works. Case 1: $a = âphhâ; $b = âpipâ; echo strcmp($a, $b); // In this case we will get result -1. As I understand it starts to compare letter by letter and when function found difference it starts to compare two values. In this case first difference found in second letter $a[1] is âhâ and $b[1] is âiâ. Difference between this number is 1 as letter âiâ goes after letter âhâ. Minus sign we get because $a < $b. Also this function stop to compare after the first difference is found. Case 2: $a = âphpâ; $b = âphpphpâ; echo strcmp($a, $b); // In this case we will get result -3. As I understand first function strcmp() as in first case starts to compare letter by letter and found that first 3 letters of two strings are similar, but as length of string $b is longer then string $a it start count the difference of symbols? $b > $a for 3 symbol so we get result -3.