← All built-ins / strcmp()

strcmp()

strcmp(string $a, string $b): int

Parameters

NameTypeDescription
$astringfirst string
$bstringsecond string

Return value

< 0 when $a sorts before $b, 0 when equal, > 0 when $a sorts after $b.

Example

echo strcmp("apple", "banana"), "
";
echo strcmp("same", "same"), "
";
echo strcmp("b", "a"), "
";
-1
0
1

See also

strcasecmp()strncmp()usort()