spacer
Web Development Tutorials PHP Tutorials
 Developer Newsletter

Tutorials
AJAX
ASP
CGI & Perl
CSS
Flash
HTML
Illustrator
Java
JavaScript
Linux
MySQL
PHP
Photoshop
Python
Wireless
XML
Miscellaneous


Scripts Directory
AJAX Scripts
ASP Scripts
ASP.NET Scripts
CGI & Perl Scripts
Flash Scripts
Java Scripts
JavaScript Scripts
PHP Scripts
Python Scripts
Remotely Hosted Scripts
Tools & Utilities Scripts
XML Scripts

Web Hosting Directory
ASP.NET
Budget
Dedicated Servers
Ecommerce
Linux
Resellers
Shared
Small Business
Windows

Developer Manuals
Learn HTML
Learn PHP
Learn CSS
Learn AJAX
Learn JavaScript
Learn Pear
Free White Papers

Developer Resources
Developer Tools
Developer Content
Survey Software
Dedicated Servers




Introduction to PHP Programming

By PHP Catalyst
2007-11-19


Data Types in PHP

In PHP a variable can hold data of any type. These data types are as following:

  • Integer - An integer is a non-fractional, whole number such as 1, 2, 3, 4, 88, 1000, 1374747. The range of integer is operating system specific.
  • Real Number - It is also known as a floating number or floating point number. It is not a whole number and has fractions such as 1.22, 2.45, 100.765 etc.
  • String - Also called character string, it consists of a series of characters such as "php".
  • Boolean - A boolean is a true or a false value.

Assigning data types

Unlike other programming languages, PHP does not require formal declaration of the data type of a variable. When you assign certain value to a variable, PHP will automatically try to guess the type of data being stored and assign the data type to the variable. When needed PHP will automatically convert the data type.

<?
$a 
5//Storing an integer
$b 5.5 //Storing a floating number
$c $a $b// $a is integer and $b is floating number
?>

Here data type of $a is automatically converted to a real number and then added with the value of $b which is a real number too.

Type Casting

Sometimes, there might be a need to change the data type of a certain variable from string to an integer and then back to a string. Such manual over riding of data types is called Type Casting. Since PHP will automatically change the data type, chances are rare that you will need to use type casting at all. To specify a different of a particular data type, use the following:

<?
$a 
= (int) $b;  //changing to a variable
$a = (string) $b;  //changing to a string
$a = (float) $b;  //changing to a real number
?>

Determining Data Type

To find out the data type of a variable, use a statement like the following:

<?
$a 
100// storing an integer
var_dump($a);
//This prints the value stored in the variable $a ?>

This will output the data type and value of the variable. In this case, the output will be int(100)



Tutorial Pages:
» What can I do with PHP?
» Popoular Features of PHP
» Basics of PHP
» Variables in PHP
» Data Types in PHP
» Expressions and Operators
» Control Structures in PHP
» Functions in PHP
» Declaring Functions in PHP
» Scope of a Variable
» Built-in Functions in PHP
» Handling Strings in PHP
» Printing Strings in PHP
» String Comparisons in PHP
» Manipulating Strings in PHP
» Arrays in PHP
» Types of Arrays in PHP
» Creating Arrays in PHP
» Array Operations in PHP


 | Bookmark Print |   Write For Us
Related Tutorials:
» Web Database Access from Desktop Applications
» CubeCart 3.0 Installation and Configuration
» PHP Site Search Made Easy
» Installing and Configuring Drupal 6.1
» Desktop Application Development with PHP-GTK
» Installing PHP on Windows



About the NetVisits, Inc Network | Write For Us | Advertise
Copyright ©2007 NetVisits, Inc Network. All Rights Reserved. Privacy Policy.
Visit other NetVisits, Inc. sites: