How to compare the two strings with Comparison Operators in PHP?
Submitted by: AdministratorPHP 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.'." ");
} else {
print('$a > $b is false.'." ");
}
if ($a == $b) {
print('$a == $b is true.'." ");
} else {
print('$a == $b is false.'." ");
}
if ($a < $b) {
print('$a < $b is true.'." ");
} else {
print('$a < $b is false.'." ");
}
?>
This script will print:
$a > $b is true.
$a == $b is false.
$a < $b is false.
Submitted by:
<?php
$a = "PHP is a scripting language.";
$b = "PHP is a general-purpose language.";
if ($a > $b) {
print('$a > $b is true.'." ");
} else {
print('$a > $b is false.'." ");
}
if ($a == $b) {
print('$a == $b is true.'." ");
} else {
print('$a == $b is false.'." ");
}
if ($a < $b) {
print('$a < $b is true.'." ");
} else {
print('$a < $b is false.'." ");
}
?>
This script will print:
$a > $b is true.
$a == $b is false.
$a < $b is false.
Submitted by:
Read Online PHP Developer Job Interview Questions And Answers
Top PHP Developer Questions
☺ | Described PHP? |
☺ | What is PEAR in PHP? |
☺ | How you can protect special characters in Query String? |
☺ | Described session in PHP? |
☺ | Described the functionality of the function strstr and stristr? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |