Skip to content

Instantly share code, notes, and snippets.

@georgeh
Created October 11, 2013 17:16
Show Gist options
  • Save georgeh/6938540 to your computer and use it in GitHub Desktop.
Save georgeh/6938540 to your computer and use it in GitHub Desktop.
Compare PHP values for truthiness - to generate http://i.imgur.com/B8R3PVK.png
graph values {
"''" -- "0"
"''" -- "0.0"
"''" -- "false"
"''" -- "null"
"'0'" -- "'0.0'"
"'0'" -- "0"
"'0'" -- "0.0"
"'0'" -- "false"
"'0.0'" -- "0"
"'0.0'" -- "0.0"
"'0.0_'" -- "0"
"'0.0_'" -- "0.0"
"'1'" -- "'1.0'"
"'1'" -- "1"
"'1'" -- "1.0"
"'1.0'" -- "1"
"'1.0'" -- "1.0"
"'1.0_'" -- "1"
"'1.0_'" -- "1.0"
"'<p/>'" -- "0"
"'<p/>'" -- "0.0"
"'<p>1</p>'" -- "0"
"'<p>1</p>'" -- "0.0"
"'<p>php</p>'" -- "0"
"'<p>php</p>'" -- "0.0"
"'php'" -- "0"
"'php'" -- "0.0"
"'_0'" -- "0"
"'_0'" -- "0.0"
"'_0.0'" -- "0"
"'_0.0'" -- "0.0"
"'_0.0_'" -- "0"
"'_0.0_'" -- "0.0"
"'_1'" -- "0"
"'_1'" -- "0.0"
"'_1.0'" -- "0"
"'_1.0'" -- "0.0"
"'_1.0_'" -- "0"
"'_1.0_'" -- "0.0"
"0" -- "0.0"
"0" -- "false"
"0" -- "null"
"0.0" -- "false"
"0.0" -- "null"
"1" -- "1.0"
"array()" -- "false"
"array()" -- "null"
"false" -- "null"
}
<?php
$values = array(
array("''", ''),
array("'0'", '0'),
array("'0.0'", '0.0'),
array("'0.0_'", '0.0_'),
array("'1'", '1'),
array("'1.0'", '1.0'),
array("'1.0_'", '1.0_'),
array("'<p/>'", '<p/>'),
array("'<p>1</p>'", '<p>1</p>'),
array("'<p>php</p>'", '<p>php</p>'),
array("'php'", 'php'),
array("'_0'", '_0'),
array("'_0.0'", '_0.0'),
array("'_0.0_'", '_0.0_'),
array("'_1'", '_1'),
array("'_1.0'", '_1.0'),
array("'_1.0_'", '_1.0_'),
array("0", 0),
array("0.0", 0.0),
array("1", 1),
array("1.0", 1.0),
array("array()", array()),
array("false", false),
array("null", null),
);
$valuesTotal = count($values);
echo "graph values {\n";
for ($i = 0; $i < ($valuesTotal - 1); $i++) {
foreach (range($i + 1, $valuesTotal - 1) as $k) {
list($baseDisplay, $base) = $values[$i];
list($compareDisplay, $compare) = $values[$k];
// echo "$i:$k Checking $baseDisplay == $compareDisplay: ";
// echo ($base == $compare)?"TRUE\n":"FALSE\n";
if ($base == $compare) {
echo '"' . $baseDisplay . '" -- "' . $compareDisplay . '"' . "\n";
}
}
}
echo "}\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment