Skip to content

Instantly share code, notes, and snippets.

@yuanqing
Last active August 29, 2015 14:03
Show Gist options
  • Save yuanqing/4fc10d752c292e096a78 to your computer and use it in GitHub Desktop.
Save yuanqing/4fc10d752c292e096a78 to your computer and use it in GitHub Desktop.
PHP: Empty, Isset, Count
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
empty($undefined); #=> true
isset($undefined); #=> false
@count($undefined); #=> 0
$null = null;
empty($null); #=> true
isset($null); #=> false
count($null); #=> 0
$string = 'foo';
empty($string); #=> false
isset($string); #=> true
count($string); #=> 1
$emptyString = '';
empty($emptyString); #=> true
isset($emptyString); #=> true
count($emptyString); #=> 1
$array = array(1);
empty($array); #=> false
isset($array); #=> true
count($array); #=> 1
$emptyArray = array();
empty($emptyArray); #=> true
isset($emptyArray); #=> true
count($emptyArray); #=> 0
$true = true;
empty($true); #=> false
isset($true); #=> true
count($true); #=> 1
$false = false;
empty($false); #=> true
isset($false); #=> true
count($false); #=> 1
$one = 1;
empty($one); #=> false
isset($one); #=> true
count($one); #=> 1
$zero = 0;
empty($zero); #=> true
isset($zero); #=> true
count($zero); #=> 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment