Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

strncmp()

Compare at most length bytes with case sensitivity and use the sign of the result.

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

Syntax

strncmp(string $string1, string $string2, int $length): int

Compare at most length bytes with case sensitivity and use the sign of the result. Matching the first N bytes does not imply the entire strings are equal. A zero length yields zero and a negative length raises ValueError.

Signature

strncmp(string $string1, string $string2, int $length): int

Example output

[0,true,true]

Examples

<?php
echo json_encode([strncmp("xyA","xyB",2),strncmp("xyA","xyB",3)<0,strncmp("A","a",1)<0]);

Result

[0,true,true]

Sources