PHP 8 reference · String Functions
PHP strcasecmp() Function
Compare two strings without caring about ASCII upper and lower case. Returns 0 if they match.
PHP 8 Since 4.0
Syntax
strcasecmp(string $string1, string $string2): int
Parameters
| Parameter | Description |
|---|---|
string1 |
The first string. |
string2 |
The second string. |
Return value
0 if equal ignoring case; negative or positive otherwise.
Examples
<?php
var_dump(strcasecmp("Hello", "hello") === 0);
var_dump(strcasecmp("apple", "Banana") < 0);
Output
bool(true) bool(true)
<?php
$cities = ["paris", "Berlin", "amsterdam"];
usort($cities, "strcasecmp");
print_r($cities);
Output
Array
(
[0] => amsterdam
[1] => Berlin
[2] => paris
)Version history
| Version | Change |
|---|---|
| PHP 4.0 | Added |
Related
strcmp()· Compare two strings byte by byte, case-sensitively. Returns 0 when equal, less than 0 or more than 0 otherwise.strnatcasecmp()· Compare strings in natural order ("a2" before "a10") while ignoring upper and lower case.- PHP Strings · tutorial