Comparing strings with strcmp() : strcmp « String « PHP






Comparing strings with strcmp()

 
<?
$x = strcmp("x54321","x5678"); 
if ($x > 0) {
    print '"x54321" is greater than the string "x5678".';
} elseif ($x < 0) {
    print '"x54321" is less than the string "x5678".';
}

$x = strcmp("54321","5678");
if ($x > 0) {
    print '"54321" is greater than the string "5678".';
} elseif ($x < 0) {
    print '"54321" is less than the string "5678".';
}

$x = strcmp('6 p','55 c');
if ($x > 0) {
    print '"6 p" is greater than than the string "55 c".';
} elseif ($x < 0) {
    print '"6 p" is less than the string "55 c".';
}

$x = strcmp('6 pack',55);
if ($x > 0) {
    print 'The string "6 pack" is greater than the number 55.';
} elseif ($x < 0) {
    print 'The string "6 pack" is less than the number 55.';
}
?>
  
  








Related examples in the same category

1.Comparing Strings
2.strcmp() function performs a case-sensitive comparison of two strings.
3.int strcmp ( string str1, string str2 ), case-insensitive sibling, strcasecmp( )
4.For example, using my collation rules (Canadian-English), I obtain the following results: