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.
2016-10-13, 472👍, 0💬
Popular Posts:
How To Create Table Borders? There are two sets of borders within a table: Outer Borders - Borders t...
How To Insert Rows Based on SELECT Statements in PHP? If want to insert rows into a table based on d...
How to install .NET Framework in Visual Studio Community 2017? I have the Visual Studio Installer in...
How To Generate and Process a Form with the Same Script in PHP? In previous exercises, a Web form is...
What is EPUB 2.0 Metadata "dc:description" Element? EPUB 2.0 Metadata "dc:description" is an optiona...