Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

strcmp()

Compare two strings lexicographically by bytes with case sensitivity.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

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

Compare two strings lexicographically by bytes with case sensitivity. A zero result means identical byte sequences. Text digits are compared lexically, so "10" sorts before "2". Rely on the sign, not the exact nonzero magnitude.

Signature

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

Example output

[true,true,0,true]

Examples

<?php
echo json_encode([strcmp("10","2")<0,strcmp("A","a")<0,strcmp("same","same"),strcmp("a\0","a")>0]);

Result

[true,true,0,true]

Sources