• PHP Video Tutorials

PHP - settype() Function


Advertisements

Definition and Usage

The function settype() set or modifies the type of a variable.

Syntax

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

Parameters

Sr.No Parameter Description
1

var

Mandatory. The variable being converted.

2

type

Mandatory. Specifies the type to convert var to.Possibles values of type are:

  • "boolean" or "bool"

  • "integer" or "int"

  • "float" or "double"

  • "string"

  • "array"

  • "object"

  • "null"

Return Values

This function returns true on success or false on failure.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of function settype():

  <?php
  $a = "tutorialspoint";
  $b = true;
  echo "***Before settype****<br>";
  var_dump($a);
  echo "<br>";
  var_dump($b);
  echo "<br>";
  settype($a, "integer"); // $a is now 0  (integer)
  settype($b, "string");  // $b is now "1" (string)
  echo "***After settype****<br>";
  var_dump($a);
  echo "<br>";
  var_dump($b);
  ?>

Output

This will produce following result −

  ***Before settype****
  string(14) "tutorialspoint"
  bool(true)
  ***After settype****
  int(0)
  string(1) "1"

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements