ຫົວຂໍ້ PHP strcmp()

ຄວາມຄິດຂອງຄົນ

ປຽບທຽບຄວາມຄິດຂອງສາຍຄຳ (ບໍ່ຄິດຄະແນນຫຍັງ):

<?php
echo strcmp("Hello world!","Hello world!");
?>

Run Instance

Definition and Usage

The strcmp() function compares two strings.

Note:The strcmp() function is binary safe and case sensitive.

Tip:This function is similar to strncmp() Functions similar, but differently, by strncmp() you can specify the number of characters of each string to compare.

Syntax

strcmp(string1,string2)
Parameters Description
string1 Required. Specifies the first string to compare.
string2 Required. Specifies the second string to compare.

Technical Details

Return value:

This function returns:

  • 0 - If two strings are equal
  • <0 - If string1 ຕໍ່າກວ່າ string2
  • >0 - If string1 ຫຼາຍກວ່າ string2
PHP Version: 4+

ຫຼາຍບົດສະຫຼຸບ

ບົດສະຫຼຸບ 1

ການປຽບທຽບສະຖິຕິສອງກະບອບ (ບໍ່ສະຫຼາດຄວາມຫຼັກກະບອບ, Hello ແລະ hELLo ບໍ່ຕົກຮູບ):

<?php
echo strcmp("Hello","Hello");
echo "<br>";
echo strcmp("Hello","hELLo");
?>

Run Instance

ບົດສະຫຼຸບ 2

ຄວາມກັບຄືນທີ່ຕ່າງກັນ:

<?php
echo strcmp("Hello world!","Hello world!"); // ສະຖິຕິສອງກະບອບບໍ່ຕົກຮູບ
echo strcmp("Hello world!","Hello"); // string1 ຫຼາຍກວ່າ string2
echo strcmp("Hello world!","Hello world! Hello!"); // string1 ຕໍ່າກວ່າ string2
?>

Run Instance