Skip to content

Instantly share code, notes, and snippets.

@damiann
Created July 9, 2014 23:16
Show Gist options
  • Save damiann/4aefb7da8f5c3e965ae5 to your computer and use it in GitHub Desktop.
Save damiann/4aefb7da8f5c3e965ae5 to your computer and use it in GitHub Desktop.
<?php
function is_true($val) {
return $val ? "true" : "false";
}
$a = 1;
$a_test = is_true($a);
echo "(a) integer : $a_test \n";
// returns: (a) integer : true
$b;
$b_test = is_true($b);
echo "(b) empty declaration : $b_test \n";
// returns: (b) empty declaration : false
$c = "1";
$c_test = is_true($c);
echo "(c) string : $c_test \n";
// returns: (c) string : true
$d = "";
$d_test = is_true($d);
echo "(d) empty string : $d_test \n";
// returns: (d) empty string : false
$e = array(1);
$e_test = is_true($e);
echo "(e) array with integer : $e_test \n";
// returns: (e) array with integer : true
$f = array("1");
$f_test = is_true($f);
echo "(f) array with string : $f_test \n";
// returns: (f) array with string : true
$g = array();
$g_test = is_true($g);
echo "(g) empty array : $g_test \n";
// returns: (g) empty array : false
$h = (object) array();
$h_test = is_true($h);
echo "(h) empty object : $h_test \n";
// returns: (h) empty object : true
$i = (object) array("test"=>true);
$i_test = is_true($i);
echo "(i) simple object : $i_test \n";
// returns: (i) simple object : true
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment