How To Compare Two Strings with strcmp()
How To Compare Two Strings with strcmp()? - PHP Script Tips - PHP Built-in Functions for Strings
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:
2007-04-21, 6579👍, 0💬
What is CodeDom? “CodeDom” is an object model which represents actually a source code. It is designe...
How do you target a specific frame from a hyperlink? Include the name of the frame in the target att...
Where are all .NET Collection classes located ? System.Collection namespace has all the collection c...
How do we get the current culture of the environment in windows and ASP.NET?
Where Is the Submitted Form Data Stored? - PHP Script Tips - Processing Web Forms When a user submit...