3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $var11 = '12345'; $var12 = '22b'; $var13 = '12345x'; $var14 = '22'; $var15 = 123456; $var16 = 22; say("string comparisons:"); comparevar('var11 and var12', $var11, $var12); comparevar('var12 and var11', $var12, $var11); say("one numeric string, one string, make string comparisons:"); comparevar('var13 and var14', $var13, $var14); comparevar('var14 and var13', $var14, $var13); say("two numeric strings make numeric comparisons:"); comparevar('var11 and var14', $var11, $var14); comparevar('var14 and var11', $var14, $var11); say("two strings make string comparisons:"); comparevar('var12 and var13', $var12, $var13); comparevar('var13 and var12', $var13, $var12); say("two numbers make numeric comparisons:"); comparevar('var15 and var16', $var15, $var16); comparevar('var16 and var15', $var16, $var15); say("one numeric string, one number, make numeric comparisons:"); comparevar('var11 and var14', $var11, $var14); comparevar('var14 and var11', $var14, $var11); comparevar('var15 and var16', $var15, $var16); comparevar('var16 and var15', $var16, $var15); function comparevar($tag, $arg1, $arg2) { echo("$tag: "); if ($arg1 === $arg2) { say("$arg1 === $arg2"); } if ($arg1 == $arg2) { say("$arg1 == $arg2"); } if ($arg1 < $arg2) { say("$arg1 < $arg2"); } if ($arg1 > $arg2) { say("$arg1 > $arg2"); } } function say($str) { echo $str, "\n"; }
based on 4R0Dv
Output for 4.3.0 - 7.1.0
string comparisons: var11 and var12: 12345 < 22b var12 and var11: 22b > 12345 one numeric string, one string, make string comparisons: var13 and var14: 12345x < 22 var14 and var13: 22 > 12345x two numeric strings make numeric comparisons: var11 and var14: 12345 > 22 var14 and var11: 22 < 12345 two strings make string comparisons: var12 and var13: 22b > 12345x var13 and var12: 12345x < 22b two numbers make numeric comparisons: var15 and var16: 123456 > 22 var16 and var15: 22 < 123456 one numeric string, one number, make numeric comparisons: var11 and var14: 12345 > 22 var14 and var11: 22 < 12345 var15 and var16: 123456 > 22 var16 and var15: 22 < 123456