String comparison using strcmp() PHP function

This tool compares two given strings and returns output by using strcmp() PHP function. All characters are taken into consideration, see definition below if you’re not sure about inputs and possible outputs.

strcmp is a binsary safe PHP function that compares two strings (string1 and string2) and returns 0 if strings are equal, <0 if string1 is less than string2, >0 if string1 is greater than string2.

 

Code example

<?php //comparison of two strings $str[] = "abc"; //string 1 $str[] = "bcd"; //string 2 $res = strcmp($str[0],$str[1]); //get result if($res==0) echo "Strings are equal to each other!"; elseif($res<0) echo "First string is less than second string!"; else echo "First string is greater than second string!"; ?>

Other tools & help

If you need help with PHP scripting, Apache setup and server-related situations, drop me a line. You’re also welcome to visit other tools - they’re listed below.