Tools, FAQ, Tutorials:
Comparing Two Strings with strcmp() in PHP
How To Compare Two Strings with strcmp()?
✍: FYIcenter.com
PHP supports 3 string comparison operators, <, ==, and >, that generates Boolean values. But if you want to get an integer result by comparing two strings, you can the strcmp() function, which compares two strings based on ASCII values of their characters. Here is a PHP script on how to use strcmp():
<?php
$a = "PHP is a scripting language.";
$b = "PHP is a general-purpose language.";
print('strcmp($a, $b): '.strcmp($a, $b)."\n");
print('strcmp($b, $a): '.strcmp($b, $a)."\n");
print('strcmp($a, $a): '.strcmp($a, $a)."\n");
?>
This script will print:
strcmp($a, $b): 1 strcmp($b, $a): -1 strcmp($a, $a): 0
As you can see, strcmp() returns 3 possible values:
⇒ Converting Strings to Hex Numbers in PHP
⇐ Converting Leading Characters to Upper Case in PHP
2016-10-13, ∼3580🔥, 0💬
Popular Posts:
What are the differences of Differences of evaluateTransaction() and submitTransaction() of the fabr...
Where to get the detailed description of the JSON.stringify() Function in JavaScript? Here is the de...
How to use the "send-one-way-request" Policy statement to call an extra web service for an Azure API...
How To Read Data from Keyboard (Standard Input) in PHP? If you want to read data from the standard i...
How to create a "Sign-up or Sign-in" user flow policy in my Azure AD B2C directory? If you want to b...