note 97138 added to ref.var
| From: | coding-kid at hotmail dot com | Date: | Sat, 03 Apr 2010 16:13:12 +0000 |
| Subject: | note 97138 added to ref.var | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167675@lists.php.net to get a copy of this message | ||
A simple method to check what type input var is:
<code>
class filter{
/*
* @var: $types (array): holds all the supported datatypes, their number, and the callback that
need to be made
* to check if it's valid.
*/
private $types = array('string'=> array('number'=> '1',
'callback'=> 'is_string'),
'int'=> array('number' => '2', 'callback' =>
'is_int'),
'array'=> array('number' => '3', 'callback'
=> 'is_array'),
'object'=> array('number' => '4', 'callback'
=> 'is_object'),
'float'=> array('number' => '5', 'callback'
=> 'is_float'),
'bool'=> array('number' => '6', 'callback'
=> 'is_bool'),
'resource'=> array('number' => '7', 'callback'
=> 'is_resource'),
'null'=> array('number' => '8', 'callback'
=> 'is_null'));
function __construct(){
}
/*
* @desc: This method checks what type the input variable is
*
* @param: $var (mixed): The var that will be checked
*
* @param: $output_type (string): How the result will be returned
*
* @returns: string or int
*/
function type($var, $output_type = 'numeric'){
if(is_string($var)){
$var_type = array("string", "1");
} elseif(is_int($var)){
$var_type = array("int", "2");
} elseif(is_array($var)){
$var_type = array("array", "3");
} elseif(is_object($var)){
$var_type = array("object", "4");
} elseif(is_float($var)){
$var_type = array("float", "5");
} elseif(is_bool($var)){
$var_type = array("bool", "6");
} elseif(is_resource($var)){
$var_type = array("resource", "7");
} elseif(is_null($var)){
$var_type = array("null", "8");
}
if($output_type == 'text'){
return $var_type[0];
} else{
return $var_type[1];
}
}
}</code>
----
Server IP: 69.147.83.197
Probable Submitter: 87.66.58.183
----
Manual Page -- http://www.php.net/manual/en/ref.var.php
Edit -- https://master.php.net/note/edit/97138
Del: integrated -- https://master.php.net/note/delete/97138/integrated
Del: useless -- https://master.php.net/note/delete/97138/useless
Del: bad code -- https://master.php.net/note/delete/97138/bad+code
Del: spam -- https://master.php.net/note/delete/97138/spam
Del: non-english -- https://master.php.net/note/delete/97138/non-english
Del: in docs -- https://master.php.net/note/delete/97138/in+docs
Del: other reasons-- https://master.php.net/note/delete/97138
Reject -- https://master.php.net/note/reject/97138
Search -- https://master.php.net/manage/user-notes.php