array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.settype.php', 1 => 'settype', 2 => 'Set the type of a variable', ), 'up' => array ( 0 => 'ref.var.php', 1 => 'Variable handling Функції', ), 'prev' => array ( 0 => 'function.serialize.php', 1 => 'serialize', ), 'next' => array ( 0 => 'function.strval.php', 1 => 'strval', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/var/functions/settype.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

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)

var_dump($foo, $bar);
?>

Примітки

Зауваження:

Maximum value for "int" is PHP_INT_MAX.

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