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, 2750🔥, 0💬
Popular Posts:
How To Avoid the Undefined Index Error in PHP? If you don't want your PHP page to give out errors as...
How to add request URL Template Parameters to my Azure API operation to make it more user friendly? ...
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
Where to get the detailed description of the json_encode() Function in PHP? Here is the detailed des...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...