ARTICLE

Gettype and Settype Function in PHP

Posted by Vinod Kumar Articles | PHP February 12, 2013
In this article I explain the settype() and gettype() functions in PHP.
Reader Level:

Introduction

In this article I explain the settype() and gettype() functions in PHP. The gettype() function gets the type of variable; gettype() is a function that display a data type. The settype function sets the type of variable; the settype() function changes the data type.

Syntax

gettype($var_name);

 

Parameter  
Var name Pass the variable name

Return Value

Boolean, Integer, Double, String, Array, Object, Resource, NULL

Example1

<?php

$a=100;

echo gettype($a);

?>

Output

 gettype in php.jpg

With Condition

 

In this example I am using "if" and "else" conditions.

 

Example2

 

<?php

$a=5;

if(is_int($a))

echo 'integer';

else

echo 'not integer';

?>

Output

gettype in php.jpg 

Next, I will explain the settype() function in PHP. Such as:

 

Syntax

 

bool settype($var_name);

 

Example

 

<?php

$a=5.2;

echo gettype($a);

echo "<br>";

settype($a,"int");

echo gettype($a);

?>

Output

Settype in PHP.jpg

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
Over-C is a holistic consortium of communications and technology specialists. We build, deploy and market both business as well as consumer products and solutions.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter