Online
 
Friday, 09 January 2009
 
 
More article:
Related Content:

Your Ad Here

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


 

Tags: Add more tags...,
This entry was posted on . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a comment. Tags: Simple PHP, Pear, Easy PHP, PHP Tutorial, PHP MySQL, XSLT, Sap Tutorial, CSS Tutorial, XSL FO Java, SQL Tutorial.
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
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

Natural 296
Statistic


Last Post

 
Top! Top!