settype

bool settype(mixed $variable, string type) 

Converts a variable to a given type.

Returns:

TRUE if the given variable can be converted to the given type; FALSE if the type argument is not a valid type name

Description:

settype() converts a variable to the specified type . If the type parameter is not a valid type name, the conversion fails and the function returns FALSE.

Availability:

UNIX, Windows

Version:

3+, 4+

See also:

To find the type of a variable:

gettype() 

Examples:

Basic use of settype()
$title = '1001 Arabian Nights'; 
settype ($title, 'integer') 
    or die ('Could not convert $title from type <i>string</i> to type 
       <i>integer</i>'); 
print $title; 
Show how setting the type modifies the value of a variable
 <pre> <?php // Make ...

Get PHP Functions Essential Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.