Skip to content

Instantly share code, notes, and snippets.

@crux
Last active August 13, 2021 09:35
Show Gist options
  • Save crux/8b74d48ad62c39b8a32a98ca0ca8c585 to your computer and use it in GitHub Desktop.
Save crux/8b74d48ad62c39b8a32a98ca0ca8c585 to your computer and use it in GitHub Desktop.
<?php
/* code below to produce the following output:
empty([ /*empty*/ ]['k']) === true
empty([ 'k'=>'' ]['k']) === true
empty([ 'k'=>true ]['k']) === false
empty([ 'k'=>23 ]['k']) === false
// so far, so good. But WTF:
empty([ 'k'=>false ]['k']) === true
empty([ 'k'=>0 ]['k']) === true
23 is not empty but 0 is? a true value is not empty, but false one is?
*/
print "empty([ /*empty*/ ]['k']) === ". (empty([ /*empty*/ ]['k']) ? 'true' : 'false') . PHP_EOL;
print "empty([ 'k'=>'' ]['k']) === ". (empty([ 'k'=>'' ]['k']) ? 'true' : 'false') . PHP_EOL;
print "empty([ 'k'=>true ]['k']) === ". (empty([ 'k'=>true ]['k']) ? 'true' : 'false') . PHP_EOL;
print "empty([ 'k'=>23 ]['k']) === ". (empty([ 'k'=>23 ]['k']) ? 'true' : 'false') . PHP_EOL;
print "empty([ 'k'=>false ]['k']) === ". (empty([ 'k'=>false ]['k']) ? 'true' : 'false') . PHP_EOL;
print "empty([ 'k'=>0 ]['k']) === ". (empty([ 'k'=>0 ]['k']) ? 'true' : 'false') . PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment