Concept

How can you compare strings by their content in PHP?

ComputerScienceOne / Arrays of Strings

"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.\n\n$x = strcmp(\"apple\", \"banana\"); //x is negative\n\n$x = strcmp(\"zelda\", \"mario\"); //x is positive"

Related Ideas

How can you compare strings by their content in PHP? | ComputerScienceOne | Bifalgorithm | Bifalgorithm