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, ∼4347🔥, 0💬
Popular Posts:
How To Remove Slashes on Submitted Input Values in PHP? By default, when input values are submitted ...
How to use "{{...}}" Liquid Codes in "set-body" Policy Statement? The "{{...}}" Liquid Codes in "set...
How to install "The Windows SDK version 8.1"? I need to build my Visual Studio C++ applications. If ...
dev.FYIcenter.com is a Website for software developer looking for software development technologies,...
How to use the "set-variable" Policy Statement to create custom variables for an Azure API service o...