Mega Code Archive

 
Categories / Php / Strings
 

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.'; } ?>