PHP strcmp() Function Last Updated : 21 Jun, 2023 Comments Improve Suggest changes Like Article Like Report Comparing two strings is one of the most commonly used string operation in programming and web development practices. The strcmp() is an inbuilt function in PHP and is used to compare two strings. This function is case-sensitive which points that capital and small cases will be treated differently, during comparison. This function compares two strings and tells us that whether the first string is greater or smaller than the second string or equals to the second string. Syntax: strcmp($string1, $string2) Parameters: This function accepts two parameters which are described below: $string1 (mandatory): This parameter refers to the first string to be used in the comparison $string2 (mandatory): This parameter refers to the second string to be used in the comparison. Return Values: The function returns a random integer value depending on the condition of match, which is given by: Returns 0 if the strings are equal. Returns a negative value (<0), if $string2 is greater than $string1. Returns a positive value (>0) if $string1 is greater than $string2. In this code we will try to understand the working of strcmp() function: PHP <?php // PHP program to illustrate the working of strcmp() $string1 = "Welcome to GFG"; $string2 = "Welcome to GeeksforGeeks"; $string3 = "Welcome to GFG"; // In this case both the strings are equal print_r(strcmp($string1, $string3)); echo "\n"; // In this case the first is greater print_r(strcmp($string2, $string1)); echo "\n"; // In this case the second is greater print_r(strcmp($string3, $string2)) ?> Output: 0 31 -31 Reference: https://www.php.net/manual/en/function.strcmp.php Comment More info C chinmoy lenka Follow Improve Article Tags : Misc Web Technologies PHP PHP-string PHP-function +1 More Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like