Comparative size of integer and floating point data in PHP
, It is more convenient, but it is more troublesome to compare strings. How to compare string data types,PHP
provides the built-in functionstrcmp()
for easy use.
Syntax:
strcmp(string $str1 , string $str2 )
$str1: The first string.
$str2: The second string.
Equal case
"; //0 ?>
Greater than case
"; // 7 ?>
If it is less than
"; // -7 ?>
The comparison of the strcmp() function is based on the ASCII code size.
Recommendation:《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of How to use strcmp() function to compare strings in PHP. For more information, please follow other related articles on the PHP Chinese website!