PHP Variable Tests

php version 5.3.29

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

$v=NULL0FALSE""TRUE11.3-1"-1"-1.7"1""1.3""0"" ""string""123str""str123""229e193427790"array()array(1)unset($v)
isset($v)falsetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruefalse
if ($v) {falsefalsefalsefalsetruetruetruetruetruetruetruetruefalsetruetruetruetruetruefalsetruefalse
 
empty($v)truetruetruetruefalsefalsefalsefalsefalsefalsefalsefalsetruefalsefalsefalsefalsefalsetruefalsetrue
 
is_scalar($v)falsetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruetruefalsefalsefalse
is_bool($v)falsefalsetruefalsetruefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalse
is_string($v)falsefalsefalsetruefalsefalsefalsefalsetruefalsetruetruetruetruetruetruetruetruefalsefalsefalse
is_int($v)falsetruefalsefalsefalsetruefalsetruefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalse
is_numeric($v)falsetruefalsefalsefalsetruetruetruetruetruetruetruetruefalsefalsefalsefalsetruefalsefalsefalse
is_float($v)falsefalsefalsefalsefalsefalsetruefalsefalsetruefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalse
is_null($v)truefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsetrue
is_array($v)falsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsetruetruefalse
 
ctype_digit($v)falsefalsefalsefalsefalsefalsefalsefalsefalsefalsetruefalsetruefalsefalsefalsefalsefalsefalsefalsefalse
ctype_alnum($v)falsefalsefalsefalsefalsefalsefalsefalsefalsefalsetruefalsetruefalsetruetruetruetruefalsefalsefalse
ctype_lower($v)falsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsetruefalsefalsefalsefalsefalsefalse
ctype_print($v)falsefalsefalsefalsefalsefalsefalsefalsetruefalsetruetruetruetruetruetruetruetruefalsefalsefalse
ctype_space($v)falsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsetruefalsefalsefalsefalsefalsefalsefalse
ctype_cntrl($v)falsetruefalsefalsefalsetruefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalsefalse
ctype_graph($v)falsefalsefalsefalsefalsefalsefalsefalsetruefalsetruetruetruefalsetruetruetruetruefalsefalsefalse
 
$v=NULL0FALSE""TRUE11.3-1"-1"-1.7"1""1.3""0"" ""string""123str""str123""229e193427790"array()array(1)unset($v)
count($v)011111111111111111010
 
gettype($v)NULLintegerbooleanstringbooleanintegerdoubleintegerstringdoublestringstringstringstringstringstringstringstringarrayarrayNULL
 
intval($v)0000111-1-1-1110001230229010
floatval($v)0000111.3-1-1-1.711.30001230INF010
strlen($v) NEW!01001132241311666130
strval($v)'''0''''''1''1''1.3''-1''-1''-1.7''1''1.3''0'' ''string''123str''str123''229e193427790''Array''Array'''
 
floor($v)0000111-1-1-2110001230INFfalsefalse0
ceil($v)0000112-1-1-1120001230INFfalsefalse0
round($v)0000111-1-1-2110001230INFfalsefalse0
$v=NULL0FALSE""TRUE11.3-1"-1"-1.7"1""1.3""0"" ""string""123str""str123""229e193427790"array()array(1)unset($v)
var_dump($v)NULL int(0) bool(false) string(0) "" bool(true) int(1) float(1.3) int(-1) string(2) "-1" float(-1.7) string(1) "1" string(3) "1.3" string(1) "0" string(1) " " string(6) "string" string(6) "123str" string(6) "str123" string(13) "229e193427790" array(0) { } array(1) { [0]=> int(1) } NULL
var_export($v)NULL0false''true11.3-1'-1'-1.7'1''1.3''0'' ''string''123str''str123''229e193427790'array ( )array ( 0 => 1, )NULL
print_r($v)'''0''''''1''1''1.3''-1''-1''-1.7''1''1.3''0'' ''string''123str''str123''229e193427790''Array ( ) ''Array ( [0] => 1 ) '''
serialize($v)'N;''i:0;''b:0;''s:0:"";''b:1;''i:1;''d:1.3;''i:-1;''s:2:"-1";''d:-1.7;''s:1:"1";''s:3:"1.3";''s:1:"0";''s:1:" ";''s:6:"string";''s:6:"123str";''s:6:"str123";''s:13:"229e193427790";''a:0:{}''a:1:{i:0;i:1;}''N;'

Hide Dumps/Include Dumps




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])truetruefalsetruefalsetruetrue
array_key_exists($key,$arr)truetruefalsetruetruetruetrue
if ($arr[$key]) {falsetruefalsetruefalsefalsefalse
 
empty($arr[$key])truefalsetruefalsetruetruetrue
 
gettype($arr[$key])integerintegerNULLstringNULLbooleanstring



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