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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

strcasecmp(string $string1, string $string2): int

Parameters

ParameterDescription
string1 The first string.
string2 The second string.

Return value

0 if equal ignoring case; negative or positive otherwise.

Examples

Ignore caseTry it yourself
<?php
var_dump(strcasecmp("Hello", "hello") === 0);
var_dump(strcasecmp("apple", "Banana") < 0);

Output

bool(true)
bool(true)
Case-insensitive sortTry it yourself
<?php
$cities = ["paris", "Berlin", "amsterdam"];
usort($cities, "strcasecmp");
print_r($cities);

Output

Array
(
    [0] => amsterdam
    [1] => Berlin
    [2] => paris
)

Version history

VersionChange
PHP 4.0Added

Was this page helpful?