The php Function Strcmp and Its Uses
The php function strcmp is an inbuilt function, which is used to compare two strings. It is a binary safe and case sensitive function that returns an integer value based on the comparison of two strings.
String comparison is one of the most common operations when working with data in PHP. It’s important to understand how this functions works and its uses in order to develop more efficient applications. This article will discuss the
The strcmp() function compares the upper and lower case versions of two strings and returns an integer value based on their comparison. The function takes the first string, $str1 and the second string, $str2 as its parameters. Both of these strings must be in the upper and lower case respectively. The function will return a negative integer value, if the first string is less than the second string, or a positive integer value, if the first string is greater than the second string.
There are many reasons to use the php function strcmp, but one of the most popular uses is for sorting arrays of strings in a case sensitive manner. Another common use is for filtering an array based on a prefix of a string. This is commonly done using the