Tools, FAQ, Tutorials:
Comparing Two Strings in PHP
How To Compare Two Strings with Comparison Operators?
✍: FYIcenter.com
PHP supports 3 string comparison operators, <, ==, and >, that generates Boolean values. Those operators use ASCII values of characters from both strings to determine the comparison results. Here is a PHP script on how to use comparison operators:
<?php
$a = "PHP is a scripting language.";
$b = "PHP is a general-purpose language.";
if ($a > $b) {
print('$a > $b is true.'."\n");
} else {
print('$a > $b is false.'."\n");
}
if ($a == $b) {
print('$a == $b is true.'."\n");
} else {
print('$a == $b is false.'."\n");
}
if ($a < $b) {
print('$a < $b is true.'."\n");
} else {
print('$a < $b is false.'."\n");
}
?>
This script will print:
$a > $b is true. $a == $b is false. $a < $b is false.
⇒ Converting Numbers to Strings in PHP
⇐ Concatenating Two Strings in PHP
2016-10-13, ∼2834🔥, 0💬
Popular Posts:
What are "*..." and "**..." Wildcard Parameters in Function Definitions? If you want to define a fun...
How to use .NET CLR Types in Azure API Policy? By default, Azure imports many basic .NET CLR (Common...
Where to find tutorials on OpenID? Here is a large collection of tutorials to answer many frequently...
Where to find tutorials on Microsoft Azure services? Here is a large collection of tutorials to answ...
How To Avoid the Undefined Index Error in PHP? If you don't want your PHP page to give out errors as...