How to use strcmp() function to compare strings in PHP

autoload
Release: 2023-03-09 11:12:01
Original
2638 people have browsed it

How to use strcmp() function to compare strings in PHP

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,PHPprovides the built-in functionstrcmp()for easy use.

Syntax:

strcmp(string $str1 , string $str2 )
Copy after login
  • $str1: The first string.

  • $str2: The second string.

Equal case

"; //0 ?>
Copy after login

Greater than case

"; // 7 ?>
Copy after login

If it is less than

"; // -7 ?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!