Concept

How does PHP compare strings using strcmp()?

ComputerScienceOne / Comparisons

"43.4. Comparisons When comparing strings in PHP, we can use the usual comparison operators such as === , < , or <= which will compare the strings lexicographically. However, this is generally discouraged because of type juggling issues and strict vs loose equality/inequality comparisons. Instead, there are several comparator methods that PHP provides to compare strings based on their content. strcmp($a, $b) takes two strings and returns an integer based on the lexicographic ordering of $a and $b . If $a precedes $b , strcmp() returns something negative. It returns zero if $a and $b have the same content. Otherwise it returns something positive if $b precedes $a . 1 $x = strcmp(\"apple\", \"banana\"); //x is negative 2 $x = strcmp(\"zelda\", \"mario\"); //x is positive 560"

Related Ideas

How does PHP compare strings using strcmp()? | ComputerScienceOne | Bifalgorithm | Bifalgorithm