Great Excess
Welcome to Great Excess arrow Website arrow php - website arrow PHP - Type Casting
Wednesday, 20 August 2008
 
 
English Language
Bahasa Indonesia
Computer
Website
Gallery
Health
Ebook
Tips
Movies

Visitor Data
Your IP
38.103.63.59
United States United States :
Browser
Unknown Browser Unknown Browser
Operating System
Unknown Operating System Unknown Operating System

PHP - Type Casting | Print |
 

PHP - Type Casting

As I already mentioned, you do not need to specify a type when you create a variable, but that doesn't mean the variables do not have types associated with them. You can explicitly set the type, known as type casting, by using the C-style syntax in which you put the type you want in brackets before the variable or expression. For example:

$var = (int)"123abc";

Without the (int) in this example, PHP creates a string variable. With the explicit cast, however, we have created an integer variable with a value of 123. The following table shows the available cast operators in PHP.

Operators

Function

(int), (integer)

Cast to an integer

(real), (double), (float)

Cash to a floating point number

(string)

Cast to a string

(array)

Cast to an array

(object)

Cast to an object

(bool), (boolean)

Cast to a boolean

(unset)

Cast to NULL; the same as calling unset( ) on the value

Although they are not usually needed, PHP does provide the following built-in functions to check variable types in your program: gettype(), is_bool(), is_long(), is_float(), is_string(), is_array(), and is_object().

 

 

This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 600
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

 
Top! Top!