3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php error_reporting(E_ALL); ?><!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP comparisions</title> <style> table { border-collapse: collapse; } th, td { margin: 0; padding: 7px; border: 1px solid #ddd; } th { font-weight: normal; } tbody th { text-align: left; } td { text-align: center; } span.true { color: green; } span.false { color: red; } </style> </head> <body> <?php $values = array( '0', '""', '"0"', 'null', 'false', 'array()', 'array(null)', 'array(false)', 'array(0)', 'array("0")' ); ?><table> <thead><tr> <th></th> <th>if(...)</th> <th>empty</th> <th>is_null</th> <th>is_numeric</th> <?php for($i = 0; $i < count($values); $i++) { $Vi = getValue($values, $i); ?><th>== <?php echo formatValue($Vi); ?></th><?php ?><th>=== <?php echo formatValue($Vi); ?></th><?php } ?> </tr></thead> <tbody><?php for($i = 0; $i < count($values); $i++) { $Vi = getValue($values, $i); ?><tr> <th><?php echo formatValue($Vi); ?></th> <td><?php echo formatCompare($Vi); ?></td> <td><?php echo formatCompare(empty($Vi)); ?></td> <td><?php echo formatCompare(is_null($Vi)); ?></td> <td><?php echo formatCompare(is_numeric($Vi)); ?></td> <?php for($j = 0; $j < count($values); $j++) { $Vj = getValue($values, $j); ?> <td><?php echo formatCompare($Vi == $Vj); ?></td> <td><?php echo formatCompare($Vi === $Vj); ?></td> <?php } ?> </tr><?php } ?></tbody> </table> </body> </html><?php function getValue($values, $index) { eval('$v = ' . $values[$index] . ';'); return $v; } function formatValue($o) { switch(gettype($o)) { case 'integer': $result = $o; break; case 'string': $result = '"' . addslashes($o) . '"'; break; case 'NULL': $result = 'null'; break; case 'boolean': $result = $o ? 'true' : 'false'; break; case 'array': $values = array(); foreach($o as $v) { $values[] = formatValue($v); } $result = 'array(' . implode(', ', $values) . ')'; break; default: die(gettype($o)); } return $result; } function formatCompare($criteria) { if($criteria) { return '<span class="true">&#x2713;</span>'; } else { return '<span class="false">&#x2717;</span>'; } }
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP comparisions</title> <style> table { border-collapse: collapse; } th, td { margin: 0; padding: 7px; border: 1px solid #ddd; } th { font-weight: normal; } tbody th { text-align: left; } td { text-align: center; } span.true { color: green; } span.false { color: red; } </style> </head> <body> <table> <thead><tr> <th></th> <th>if(...)</th> <th>empty</th> <th>is_null</th> <th>is_numeric</th> <th>== 0</th><th>=== 0</th><th>== ""</th><th>=== ""</th><th>== "0"</th><th>=== "0"</th><th>== null</th><th>=== null</th><th>== false</th><th>=== false</th><th>== array()</th><th>=== array()</th><th>== array(null)</th><th>=== array(null)</th><th>== array(false)</th><th>=== array(false)</th><th>== array(0)</th><th>=== array(0)</th><th>== array("0")</th><th>=== array("0")</th> </tr></thead> <tbody><tr> <th>0</th> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>""</th> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>"0"</th> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>null</th> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>false</th> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>array()</th> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>array(null)</th> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>array(false)</th> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>array(0)</th> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> </tr><tr> <th>array("0")</th> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="false">&#x2717;</span></td> <td><span class="true">&#x2713;</span></td> <td><span class="true">&#x2713;</span></td> </tr></tbody> </table> </body> </html>