I am explaining you, how to compare two string in PHP by using the strcmp() function. it is case-sensitive function.
strcmp() function will take two string as parameter string1 and string2. if function will return < 0 then the first string is less than the second string, if it will return > 0 then the first string is greater than a second string and if it will return 0 then both strings are equal.
Syntax :
strcmp(string1,string2)
string1 : it is required. it specifies the first string for comparison.
string2 : it is required. it specifies the second string for comparison.
Example :
<?php
echo strcmp("Hello Webdeveloperindia!","Hello Webdeveloperindia!"); //here both strings are equal
echo "<br>";
echo strcmp("Hello Webdeveloperindia!","Hello"); //here string1 is greater than string2
echo "<br>";
echo strcmp("Hello","Hello Webdeveloperindia India! "); //here string1 is less than string2
?>
OutPut :
0
19
-26
Hello, Welcome to webdeveloperindia.in. I am a full-stack web developer. Email – [email protected] | Skype – azaruddin23. I have knowledge of PHP, Laravel, Magento 1/2, Codeigniter, WordPress, Joomla, Shopify, Git, Bitbuket, jQuery, Ajax, Javascript and ReactJS.