settype

(PHP 4, PHP 5, PHP 7, PHP 8)

settypeSet the type of a variable

Опис

settype(mixed &$var, string $type): bool

Set the type of variable var to type.

Параметри

var

The variable being converted.

type

Possibles values of type are:

  • "boolean" or "bool"
  • "integer" or "int"
  • "float" or "double"
  • "string"
  • "array"
  • "object"
  • "null"

Значення, що повертаються

Повертає true у разі успіху або false в разі помилки.

Приклади

Приклад #1 settype() example

<?php
$foo
= "5bar"; // string
$bar = true; // boolean

settype($foo, "integer"); // $foo is now 5 (integer)
settype($bar, "string"); // $bar is now "1" (string)
?>

Примітки

Зауваження:

Maximum value for "int" is PHP_INT_MAX.

Прогляньте також