How to use php strncmp function?

藏色散人
Release: 2023-02-22 22:36:01
Original
2791 people have browsed it

php The strncmp function is used to compare two strings. Its syntax is strncmp(string1,string2,length). The parameter string1 is required and refers to the first string to be compared; string2 is required and refers to the second string to be compared. string.

How to use php strncmp function?

php How to use strncmp function?

Definition and usage

strncmp() function compares two strings.

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

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

Syntax

strncmp(string1,string2,length)
Copy after login

Parameters

string1 Required. Specifies the first string to compare.

string2 Required. Specifies the second string to be compared.

length Required. Specifies the number of characters of each string used in the comparison.

Return value:

This function returns:

0 - if the two strings are equal

<0 - if string1 is less than string2

>0 - if string1 is greater than string2

PHP version: 4

Example 1

Compare two String (case sensitive, China and CHINA output are different):

"; echo strncmp("China","CHINA",6); ?>
Copy after login

Output:

0 1
Copy after login

Example 2

Compare two strings (case sensitive):

Copy after login

Output:

0
Copy after login

The above is the detailed content of How to use php strncmp function?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!