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:
2016-10-13, 1147👍, 0💬
Popular Posts:
Where to find tutorials on Python programming language? I want to learn Python. Here is a large coll...
How To Support Multiple-Page Forms in PHP? If you have a long form with a lots of fields, you may wa...
How to create Hello-3.0.epub with WinRAR? I have all required files to create Hello-3.0.epub. To cre...
What is Azure API Management Publisher Portal 2017 version? Azure API Management Publisher Portal is...
How to add request body examples to my Azure API operation 2017 version to make it more user friendl...