Home >Backend Development >PHP Tutorial >Introduction to the usage of PHP string comparison functions strcmp() and strcasecmp()

Introduction to the usage of PHP string comparison functions strcmp() and strcasecmp()

WBOY
WBOYOriginal
2016-07-25 08:59:181040browse
  1. $a = "joe";
  2. $b = "jerry";
  3. if ($a != $b)
  4. {
  5. echo "not equal";
  6. }
  7. else
  8. {
  9. echo "Equal";
  10. }
  11. ?>
Copy code

If you use !==, === to compare, the types of the two objects must be strictly equal to return true; otherwise, use ==, != will automatically convert the string into the corresponding type for comparison.

  1. echo strnatcmp("10.gif", "5.gif"); // Return 1 (>0)
  2. echo strnatcasecmp("10.gif", "5.gif "); // Return 1 (>0)
  3. ?>
Copy code


Statement:
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