PHP code example of angle / falsy
1. Go to this page and download the library: Download angle/falsy library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
angle / falsy example snippets
falsy(true, false, null); // true
truthy(true, false, null); // false
falsy(true, 1, [1]); // false
truthy(true, 1, [1]); // true
falsy('0', '', [], ['']); // true
truthy('0', '', [], ['']); // false
// Note: (bool) [''] returns true in plain PHP. Falsy interprets it as false, as it should.
$array = [
'foo' => false,
'bar'=> [
'baz' => false
]
];
falsy($array); // true
truthy($array); // false
$array = [
'foo' => true,
'bar'=> [
'baz' => 1
]
];
falsy($array); // false
truthy($array); // true
$object = new stdClass;
falsy($object); // true
truthy($object); // false
$object->foo = false;
$object->bar = null;
$object->baz = 0;
falsy($object); // true
truthy($object); // false
$object->foo = true;
$object->bar = 'string';
$object->baz = 1;
falsy($object); // false
truthy($object); // true
$void = function () { return; };
falsy($void); // true
truthy($void); // false
$false = function () { return false; };
falsy($false); // true
truthy($false); // false
$string = function () { return 'string'; };
falsy($string); // false
truthy($string); // true
falsy($void, $false, $string); // true
truthy($void, $false, $string); // false
falsy(
false,
null,
0,
0.0,
'0',
[],
[''], // Php would consider this as being true, but really, is it? No.
['' => ''],
[false, null],
['' => '', 0 => ['key' => null, 'foo' => [''], 'empty' => []]], // Array keys are ignored
new stdClass, // Objects with empty attributes are falsy
function () { return; }, // Void closures are falsy
function () { return false; },
function () { return null; },
function () { return ''; },
function () { return 0; },
function () { return []; },
function () { return ['']; }
); // true
$object = new stdClass;
$object->foo = 'bar';
truthy(
true,
1,
0.1,
'1',
['foo'],
['foo' => 'bar'],
[true],
$object,
function () { return true; },
function () { return 1; },
function () { return 0.1; },
function () { return '1'; },
function () { return ['foo']; },
function () { return ['foo' => 'bar']; },
function () { return [true]; },
function () use ($object) { return $object; }
); // true