-
-
-
-
function:gettype ( varname );
return type:string
content:ใช้คืนค่าชนิดข้อมูลของตัวแปร
example:$num = 1.2e3;
echo gettype ( $num );
comment:ชนิดตัวแปรที่เป็นไปได้ของ php ได้แก่ real, float, boolean, integer, double, string,
array, object, resource, null, user function, unknown type
-
function:settype ( varname, new_type );
return type:void, boolean
content:ใช้กำหนด ชนิดข้อมูลใหม่ ให้กับตัวแปร และจะคืนค่า true กลับมาถ้าหากว่าเปลี่ยนชนิดตัวแปรสำเร็จ
example:$num = 1.234;
settype ( $num, "integer" );
comment:นอกจากนี้ยังมีอีกวิธีหนึ่งในการแปลงชนิดตัวแปร คือวิธีการ casting
ดังนี้ ( type ) varname;
เช่น ( integer ) $num;
-
function:get_defined_constants ( categorize );
return type:array
content:ใช้คืนค่า ค่าคงที่ทั้งหมด
example:print_r ( get_defined_constants() );
comment:ถ้ากำหนด categorize = true จะมีการแบ่งชนิดตัวแปรตามหมวดหมู่
-
function:get_defined_vars ();
return type:array
content:ใช้คืนค่า ตัวแปรทั้งหมด ที่มีการประกาศใช้
example:$name = "bamboolabcode";
$food = array( "water"=>"ovaltine", "rice"=>"pizza" );
print_r ( get_defined_vars() );
-
function:get_resource_type ( resource );
return type:string
content:ใช้คืนค่าประเภทของตัวแปร resource
example:$conn = mysql_connect();
$fp = fopen ( "bamboo.txt", "w" );
echo get_resource_type ( $conn );
echo get_resource_type ( $fp );
-
function:isset ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น ได้ประกาศไว้แล้วหรือไม่
example:if ( isset ( $name ) )
{
echo "already";
}
-
function:empty ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น empty ใช่หรือไม่ ( คือ ค่าว่าง หรือ ศุนย์ )
example:$price = 0;
if ( empty ( $price ) )
{
echo "empty bath";
}
-
function:unset ( varname1, varname2, ..., varname3 );
return type:void
content:ใช้ยกเลิกตัวแปร ( คืนค่าหน่วยความจำของตัวแปรนั้นๆ )
example:$num = 500.00;
unset ( $num );
-
function:strval ( varname );
return type:string
content:ใช้แปลง ตัวแปรที่กำหนด ให้เป็น string
example:$price = strval ( 200 );
echo gettype ( $price );
-
function:intval ( varname );
return type:int
content:ใช้แปลง ตัวแปรที่กำหนด ให้เป็น int
example:$num = intval ( pi() );
echo gettype ( $num );
-
function:floatval ( varname );
return type:float
content:ใช้แปลง ตัวแปรที่กำหนด ให้เป็น float
example:$num = "500.00bath";
echo gettype ( $num );
-
function:eval ( string );
return type:void
content:ใช้แปลง string ที่กำหนดให้เป็น code php และจะประมวลผลตาม code ที่ได้
example:eval ( "echo 'Hello BambooLabcode';" );
eval ( "$num = 500.00;" );
echo $num;
-
function:is_string ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น string ใช่หรือไม่
example:if ( is_string ( 500 ) )
{
echo "var type string";
}
-
function:is_numeric ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น ตัวเลข ใช่หรือไม่
example:if ( is_numeric ( 500 ) )
{
echo "var type number";
}
-
function:is_int ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น เลขจำนวนเต็ม ใช่หรือไม่
example:if ( is_int ( 300.00 ) )
{
echo "var type natural number";
}
-
function:is_integer ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น เลขจำนวนเต็ม ใช่หรือไม่
example:if ( is_integer ( 300.00 ) )
{
echo "var type natural number";
}
-
function:is_long ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น เลขจำนวนเต็ม ใช่หรือไม่
example:if ( is_long ( 300.00 ) )
{
echo "var type natural number";
}
-
function:is_float ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น เลขจำนวนจริง ใช่หรือไม่
example:if ( is_float ( 300.00 ) )
{
echo "var type real number";
}
-
function:is_double ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น เลขจำนวนจริง ใช่หรือไม่
example:if ( is_double ( 300.00 ) )
{
echo "var type real number";
}
-
function:is_real ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น เลขจำนวนจริง ใช่หรือไม่
example:if ( is_real ( 300.00 ) )
{
echo "var type real number";
}
-
function:is_bool ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น boolean ใช่หรือไม่
example:if ( is_bool ( 1 ) )
{
echo "var type boolean";
}
-
function:is_array ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น array ใช่หรือไม่
example:$arr = array ( "bamboo", "lab", "code" );
if ( is_array ( $arr ) )
{
echo "var type array";
}
-
function:is_resource ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น resource ใช่หรือไม่
example:$conn = mysql_connect();
if ( is_resource ( $conn ) )
{
echo "var type resource";
}
-
function:is_object ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น object ใช่หรือไม่
example:if ( is_object ( "bamboolabcode" ) )
{
echo "var type object";
}
-
function:is_null ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น null ใช่หรือไม่
example:if ( is_null ( "bamboolabcode" ) )
{
echo "var type null";
}
-
function:is_scalar ( varname );
return type:boolean
content:ใช้ตรวจสอบว่า ตัวแปรนั้น เป็น scalar ใช่หรือไม่
example:if ( is_scalar ( "bamboolabcode" ) )
{
echo "var type scalar";
}
comment:scalar คือตัวแปรที่มีค่าเดียว เป็นได้ทั้งตัวเลขและตัวอักษร
( ไม่รวม array, resource, object, null )
-
function:serialize ( varname );
return type:string
content:ใช้แปลงข้อมูลที่กำหนด ให้อยู่ในรูป byte-stream
นิยมนำมาใช้กับ object ที่สร้างจาก class เพื่อใช้ในการส่งข้อมูล
example:$string = "bamboo";
echo serialize ( $object );
comment:รูป byte-stream เช่น s:6:"bamboo"
-
function:unserialize ( string );
return type:mixed
content:ใช้แปลงข้อมูลในรูป byte-stream ให้กลับมาเป็นตัวแปรก่อนถูกแปลง
example:$stream = serialize ( "bamboo" );
echo unserialize ( $stream );