Hàm settype() trong PHP
Ví dụ
Chuyển đổi các biến thành các loại cụ thể:
<?php
$a = "32"; // string
settype($a, "integer"); // $a is now integer
$b = 32;
// integer
settype($b, "string"); // $b is now string
$c = true; //
boolean
settype($c, "integer"); // $c is now integer (1)
?>
Hãy tự mình thử »Định nghĩa và cách sử dụng
Hàm settype() chuyển đổi một biến thành một kiểu cụ thể.
Cú pháp
settype( variable , type );
Giá trị tham số
Parameter | Description |
---|---|
variable | Required. Specifies the variable to convert |
type | Required. Specifies the type to convert variable to. The possible types are: boolean, bool, integer, int, float, double, string, array, object, null |
Chi tiết kỹ thuật
Giá trị trả về: | ĐÚNG nếu thành công, SAI nếu thất bại |
---|---|
Kiểu trả về: | Boolean |
Phiên bản PHP: | 4.0+ |
❮ Tham chiếu xử lý biến PHP