Home > Backend Development > PHP Tutorial > strcmp() function in PHP

strcmp() function in PHP

WBOY
Release: 2023-08-31 09:10:01
forward
1300 people have browsed it

strcmp() function in PHP

strcmp() function is used to compare two strings.

Note - This function is case sensitive.

Syntax

strcmp(str1, str2)
Copy after login

Parameters

  • str1 - The first string to compare

  • < strong>str2 - The second string to compare

Returns

The strcmp() function returns -

  • 0 - if the two strings are equal

  • <0 - if string1 is less than string2<0 - 如果 string1 小于 string2

  • < li>

    >0 - If string1 is greater than string2

Example

The following is an example-

Live demonstration

<?php
   echo strcmp("windows","Windows");
?>
Copy after login

Output

The following is the output -

32
Copy after login

Example

Let’s see another example-

Live Demonstration

<?php
   echo strcmp("Windows OS","Windows Operating System");
?>
Copy after login

Output

Here is the output-

-7424
Copy after login

The above is the detailed content of strcmp() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template