String comparison function; comparison function; string comparison

php strncmp() function syntax

Function:Compare the first n characters of the string, case sensitive

Syntax: strncmp(string1,string2,length)

Parameters:

ParametersDescription
string1 Required, specifies the first string to be compared.
string2Required, specifies the second string to be compared.
#lengthRequired, specifies the number of characters in each string used in the comparison.

Description: strncmp() function compares two strings. strncmp() is binary-safe and case-sensitive. If the two strings are equal, 0 is output. If string1 is greater than string2, the output value is greater than 0. If string1 is less than string2, the output value is less than 0.

php strncmp() function example

<?php
echo strncmp("helloworld","Helloworld",6);
?>

Run instance»

Click the "Run instance" button to view the online instance

Output:

1