PHP strcmp() Function: Usage, Parameters, Return Values, and Examples
This article explains the PHP strcmp() function, describing its binary‑safe, case‑sensitive string comparison behavior, detailing its parameters and return values, and providing multiple code examples that illustrate how different string inputs affect the function’s output.
The PHP strcmp() function compares two strings in a binary‑safe, case‑sensitive manner and returns an integer indicating their lexical relationship.
Parameters
string $str1 : The first string.
string $str2 : The second string.
Return values
Less than 0 if $str1 is less than $str2 .
Greater than 0 if $str1 is greater than $str2 .
0 if the strings are equal.
Example 1
";
echo strcmp("Hello", "hELLo");
?>Output:
// 0
// < 0 (because "Hello" is less than "hELLo" in binary comparison)Example 2
$str2
?>Output:
// 0
// positive integer (e.g., 7)Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.