본문 바로가기

Development/Coding

PHP Variable Tests

PHP Variable Tests

php version 5.1.6

version for 5.0.4 (as at 26/09/2005)

$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
isset($v) false true true true true true true true true true
if ($v) { false false false false true true true true true true
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
isset($v) true true true true true true true true true false
if ($v) { true true false true true true true false true false
 
$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
empty($v) true true true true false false false false false  
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
empty($v) false false true false false false false true false true
 
$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
is_scalar($v) false true true true true true true true true true
is_bool($v) false false true false true false false false false false
is_string($v) false false false true false false false false true false
is_int($v) false true false false false true false true false false
is_numeric($v) false true false false false true true true true true
is_float($v) false false false false false false true false false true
is_null($v) true false false false false false false false false false
is_array($v) false false false false false false false false false false
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
is_scalar($v) true true true true true true true false false false
is_bool($v) false false false false false false false false false false
is_string($v) true true true true true true true false false false
is_int($v) false false false false false false false false false false
is_numeric($v) true true true false false false false false false false
is_float($v) false false false false false false false false false false
is_null($v) false false false false false false false false false true
is_array($v) false false false false false false false true true false
 
$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
ctype_digit($v) false false false false false false false false false false
ctype_alnum($v) false false false false false false false false false false
ctype_lower($v) false false false false false false false false false false
ctype_print($v) false false false false false false false false true false
ctype_space($v) false false false false false false false false false false
ctype_cntrl($v) false true false false false true false false false false
ctype_graph($v) false false false false false false false false true false
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
ctype_digit($v) true false true false false false false false false false
ctype_alnum($v) true false true false true true true false false false
ctype_lower($v) false false false false true false false false false false
ctype_print($v) true true true true true true true false false false
ctype_space($v) false false false true false false false false false false
ctype_cntrl($v) false false false false false false false false false false
ctype_graph($v) true true true false true true true false false false
 
$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
count($v) 0 1 1 1 1 1 1 1 1 1
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
count($v) 1 1 1 1 1 1 1 0 1 0
 
$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
gettype($v) NULL integer boolean string boolean integer double integer string double
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
gettype($v) NULL integer boolean string boolean integer double integer string double
 
$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
intval($v) 0 0 0 0 1 1 1 -1 -1 -1
floatval($v) 0 0 0 0 1 1 1.3 -1 -1 -1.7
strlen($v) NEW! 0 1 0 0 1 1 3 2 2 4
strval($v) '' '0' '' '' '1' '1' '1.3' '-1' '-1' '-1.7'
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
intval($v) 1 1 0 0 0 123 0 0 1 0
floatval($v) 1 1.3 0 0 0 123 0 0 1 0
strlen($v) NEW! 1 3 1 1 6 6 6 5 5 0
strval($v) '1' '1.3' '0' ' ' 'string' '123str' 'str123' 'Array' 'Array' ''
 
$v= NULL 0 FALSE "" TRUE 1 1.3 -1 "-1" -1.7
floor($v) 0 0 0 0 1 1 1 -1 -1 -2
ceil($v) 0 0 0 0 1 1 2 -1 -1 -1
round($v) 0 0 0 0 1 1 1 -1 -1 -2
$v= "1" "1.3" "0" " " "string" "123str" "str123" array() array(1) unset($v)
floor($v) 1 1 0 0 0 123 0 false false 0
ceil($v) 1 2 0 0 0 123 0 false false 0
round($v) 1 1 0 0 0 123 0 false false 0



Accessing Array Key/Values

$arr = array (
  'zero' => 0,
  'one' => 1,

  'three' => 'Three',
  'null' => NULL,
  'false' => false,
  'empty' => '',
);   
$key = 'zero' 'one' 'two' 'three' 'null' 'false' 'empty'
isset($arr[$key]) true true false true false true true
array_key_exists($key,$arr) true true false true true true true
if ($arr[$key]) { false true false true false false false
 
empty($arr[$key]) true false true false true true true
 
gettype($arr[$key]) integer integer NULL string NULL boolean string



In case interested all these tests are carried out live as this page is rendered (with a bit of 'eval'), so any upgrade of PHP will immediately showup. If you have a different version of PHP, and would like to host a copy then let me know at the link below.

Hosted at deformedweb.co.uk. Comments/Suggestions/Donations etc to Barry (c)2005


또 다른 링크 
http://www.blueshoes.org/en/developer/php_cheat_sheet/