PHP/Data Type/Data Type
Содержание
Create Object and check its type
<?php
class employee {
var $emp_code;
var $name;
var $address;
var $department;
var $sex;
var $date_of_birth;
var $salary;
}
$dave = new employee;
$alice = new employee;
echo(is_object($dave));
?>
Create Object and get its type
<?php
class employee {
var $emp_code;
var $name;
var $address;
var $department;
var $sex;
var $date_of_birth;
var $salary;
}
$dave = new employee;
$alice = new employee;
echo gettype ($dave)," \n";
echo gettype ($alice), " \n";
?>
gettype() and settype() Data Types
Data Type Returned by gettype Set by settype
----------------------------------------------------------------------------------
Array Array Array
Boolean Boolean Boolean
Double Double Double
Integer Integer Integer
Null Null N/A
Object Object Object
Resource Resource N/A
String String String
Unknown Unknown type N/A
is_numeric in action
<?php
$item = 43;
echo "The variable \$item is numeric: ".is_numeric($item)."<br />";
?>
PHP Data Types
Type Description
Boolean Possible values are True and False.
Float Floating-point values.
Integer Integer values.
String Any series of ASCII characters 0?255. PHP strings are binary safe.
Array An indexed list of other values. All data types are allowed as values.
Object A class instance.
Resource A handle to an internal data structure. This can be a database connection or a result set.
Returns true if $a is a floating-point number
<?
$a = 0.1;
echo( is_double($a) );
?>
Returns true if $a is an array
<?
$a=array(0=>"zzzz",
"a"=>"aaa",
"b"=>"bbb",
"c"=>"ccc");
echo(is_array($a));
?>
Returns true if $a is an integer
<?
$a = 0;
echo(is_integer($a));
?>
Returns true if $a is a string
<?
$a = "aa";
echo(is_string($a));
?>