Easy Tutorial
❮ Func Math Round Php Form Url Email ❯

PHP strncmp() Function

PHP String Reference Manual

Example

Compare two strings (case-sensitive):


Definition and Usage

The strncmp() function compares two strings (case-sensitive).

Note: strncmp() is binary-safe and case-sensitive.

Tip: This function is similar to the strcmp() function, except that strcmp() does not have the length parameter.


Syntax

Parameter Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to compare.
length Required. Specifies the number of characters from each string to use in the comparison.

Technical Details

Return Value: The function returns: 0 - if the two strings are equal<br> <0 - if string1 is less than string2<br> >0 - if string1 is greater than string2
PHP Version: 4+
--- ---

More Examples

Example 1

Compare two strings (case-sensitive, Hello and hELLo output different results):


❮ Func Math Round Php Form Url Email ❯