Skip to content

Instantly share code, notes, and snippets.

@barryhughes
Created August 8, 2024 00:04
Show Gist options
  • Save barryhughes/5cc5f6c17de2e60eae55c8911931de67 to your computer and use it in GitHub Desktop.
Save barryhughes/5cc5f6c17de2e60eae55c8911931de67 to your computer and use it in GitHub Desktop.
<?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