Created
August 8, 2024 00:04
-
-
Save barryhughes/5cc5f6c17de2e60eae55c8911931de67 to your computer and use it in GitHub Desktop.
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 | |
$tests = [ | |
true, | |
false, | |
-1, | |
0, | |
1, | |
-5.0, | |
1.0, | |
5, | |
'-5', | |
'0', | |
'1', | |
'', | |
' ', | |
'abc', | |
[], | |
[ 1 ], | |
(object) [], | |
(object) [ 'foo' => 'bar' ], | |
]; | |
print 'FILTER CAST' . PHP_EOL; | |
foreach ( $tests as $test_value ) { | |
print filter_var( $test_value, FILTER_VALIDATE_BOOL ) ? '1' : '0'; | |
print ' '; | |
print $test_value ? '1' : '0'; | |
print PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment