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, ∼4279🔥, 0💬
Popular Posts:
How to access Request body from "context.Request.Body" object in Azure API Policy? Request body is t...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
What is Fabric CA (Certificate Authority)? Fabric CA (Certificate Authority) is a component of Hyper...
How to use the "forward-request" Policy Statement to call the backend service for an Azure API servi...
How to run PowerShell Commands in Dockerfile to change Windows Docker images? When building a new Wi...