Support PHP Version: PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, PHP 8.1, PHP 8.2, PHP 8.3 With Latest All Version Support.
Hello Friends Today, through this tutorial, I will tell you How to Use `strcasecmp()` function using PHP, PHP 8, PHP 8.1, PHP 8.2 With Example. In PHP, `strcasecmp()` is a function used to compare two strings in a case-insensitive manner. This function is available in both PHP. It returns 0 if the two strings are equal ignoring case, a negative value if the first string is less than the second string, and a positive value if the first string is greater than the second string.
Here’s an example demonstrating the usage of `strcasecmp()`:
<?php $string1 = "Hello"; $string2 = "hello"; // Case-insensitive comparison $result = strcasecmp($string1, $string2); if ($result === 0) { echo "The strings are equal."; } elseif ($result < 0) { echo "The first string is less than the second string."; } else { echo "The first string is greater than the second string."; } ?>
In this example, the output will be “The strings are equal.” because `strcasecmp()` performs a case-insensitive comparison, considering “Hello” and “hello” as equal strings.