Last active
October 15, 2020 06:13
-
-
Save timotheemoulin/02013b006b701d1a684ded46aab06f4c to your computer and use it in GitHub Desktop.
Does PHP evaluate things the way you thought?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// counting values | |
var_dump(count(array())); // 0 | |
var_dump(count(false)); // 1 | |
var_dump(count(true)); // 1 | |
var_dump(count(null)); // 0 | |
var_dump(count(1)); // 1 | |
var_dump(count(0)); // 1 | |
var_dump(count('asdf')); // 1 | |
// checking array values (in_array) | |
var_dump(in_array(true, ['foo', 'bar', ])); // true | |
var_dump(in_array(1, [true])); // true | |
var_dump(in_array(1, [true]), true); // false (use the $strict parameter) | |
// substracting floats | |
var_dump(1 - 0.99); //float(0.01) | |
var_dump(10 - 9.99); //float(0.0099999999999998) | |
var_dump(10 - 10.01); //float(-0.0099999999999998) | |
// casting function return values | |
function returnbool():bool{ | |
return -1; | |
} | |
function returnint():int{ | |
return false; | |
} | |
var_dump(returnbool()); // bool(true) | |
var_dump(returnint()); // int(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment