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, ∼2612🔥, 0💬
Popular Posts:
Where can I download the EPUB 2.0 sample book "The Metamorphosis" by Franz Kafka? You can following ...
Why I am getting "LNK1104: cannot open file 'MSCOREE.lib'" error when building a C++/CLI program? Vi...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...
How To Pass Arrays By References? in PHP? Like normal variables, you can pass an array by reference ...