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, ∼4305🔥, 0💬
Popular Posts:
What is Azure API Management Gateway? Azure API Management Gateway is the Azure Web server that serv...
Why I am getting "LNK1104: cannot open file 'MSCOREE.lib'" error when building a C++/CLI program? Vi...
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
How To Copy Array Values to a List of Variables in PHP? If you want copy all values of an array to a...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...