PHP strcmp() ফাংশন

উদাহরণ

দুই স্ট্রিংকে তুলনা করুন (ক্ষতিগ্রস্ত হয়না):

<?php
echo strcmp("Hello world!","Hello world!");
?>

Run Instance

Definition and Usage

The strcmp() function compares two strings.

Comment:The strcmp() function is binary safe and case sensitive.

Tip:This function is similar to strncmp() The function is similar, but differently, by using strncmp() you can specify the number of characters used for comparison in each string.

Syntax

strcmp(string1,string2)
Parameter Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to compare.

Technical Details

Return value:

This function returns:

  • 0 - If two strings are equal
  • <0 - If string1 Less than string2
  • >0 - If string1 Greater than string2
PHP Version: 4+

More Examples

Example 1

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

<?php
echo strcmp("Hello","Hello");
echo "<br>";
echo strcmp("Hello","hELLo");
?>

Run Instance

Example 2

Different return values:

<?php
echo strcmp("Hello world!","Hello world!"); // Two strings are equal
echo strcmp("Hello world!","Hello"); // string1 Greater than string2
echo strcmp("Hello world!","Hello world! Hello!"); // string1 Less than string2
?>

Run Instance