3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $var11 = '12345'; $var12 = '22b'; $var13 = '12345x'; $var14 = '22'; $var15 = 12345; $var16 = 22; $var17 = '22c'; $var18 = '22a'; $var19 = '12345m'; $var20 = '12345z'; say("string comparisons:"); comparevar('var11 and var12', $var11, $var12); say("one numeric string, one string, make string comparisons:"); comparevar('var13 and var14', $var13, $var14); say("two numeric strings make numeric comparisons:"); comparevar('var11 and var14', $var11, $var14); say("two strings make string comparisons:"); comparevar('var12 and var13', $var12, $var13); say("two numbers make numeric comparisons:"); comparevar('var15 and var16', $var15, $var16); say("one numeric string, one number, make numeric comparisons:"); comparevar('var11 and var14', $var11, $var14); comparevar('var15 and var16', $var15, $var16); comparevar('var11 and var15', $var11, $var15); comparevar('var16 and var14', $var16, $var14); say("one string, one number, make numeric comparisons:"); comparevar('var13 and var15', $var13, $var15); comparevar('var12 and var16', $var12, $var16); comparevar('var13 and var16', $var13, $var16); comparevar('var15 and var12', $var15, $var12); say("and then some weirdness"); comparevar('var13 and var14', $var13, $var14); comparevar('var13 and var16', $var13, $var16); comparevar('var14 and var16', $var14, $var16); comparevar('var17 and var16', $var17, $var16); comparevar('var18 and var16', $var18, $var16); comparevar('var17 and var18', $var17, $var18); 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"); } if (((! ($arg1 < $arg2)) != ($arg1 > $arg2)) and ($arg1 != $arg2)) {say("screwy 1");} if (((! ($arg1 < $arg2)) != ($arg2 < $arg1)) and ($arg1 != $arg2)) {say("screwy 2");} } function say($str) { echo $str, "\n"; }
based on EEviI
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string comparisons: var11 and var12: 12345 < 22b one numeric string, one string, make string comparisons: var13 and var14: 12345x < 22 two numeric strings make numeric comparisons: var11 and var14: 12345 > 22 two strings make string comparisons: var12 and var13: 22b > 12345x two numbers make numeric comparisons: var15 and var16: 12345 > 22 one numeric string, one number, make numeric comparisons: var11 and var14: 12345 > 22 var15 and var16: 12345 > 22 var11 and var15: 12345 == 12345 var16 and var14: 22 == 22 one string, one number, make numeric comparisons: var13 and var15: 12345x == 12345 var12 and var16: 22b == 22 var13 and var16: 12345x > 22 var15 and var12: 12345 > 22b and then some weirdness var13 and var14: 12345x < 22 var13 and var16: 12345x > 22 var14 and var16: 22 == 22 var17 and var16: 22c == 22 var18 and var16: 22a == 22 var17 and var18: 22c > 22a