phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP Basic: Casting Type

Tag: data type, cast   Category: PHP Basic
post: 01 Mar 2008 read: 406


PHP Basic Data Type Step By Step Tutorial - Part 10: Casting type represents the guidance process of a data which save in one variable according to the instructed data type. The process of casting runs together with the instruction of the data type operator

Operator Casting

Operator Info
(int), (integer) Pointing at integer
(bool), (boolean) Pointing at Boolean
(float), (double), (real) Pointing at Float
(string) Pointing at String
(array) Pointing at Array
(object) Pointing at Object

Pay attention to the example of using casting type at script as following:
File name: casting.php


<html>
<head>
<title> Casting Type </title>
</head>
<body> 
<h1>Comprehending result without Casting</h1>
<? 
$price = "50000";
$amount = "10 pack";
$pay = $price * $amount;
echo "\$price = $price <br>";
echo "\$amount = $amount <br>";
echo "\$pay = $pay <br><br>";
echo "<h1>Comprehending result with Casting</h1>";
$amnt = (integer) $amount;
echo "\$price = $price <br>";
echo "\$amount = $amnt <br>";
echo "\$pay = $pay <br>";
?>
</body>
</html>
</body>
</html>

Execute casting.php program and the result will be:

php basic casting type

Casting type is almost rare to be used. It is caused by the automatic conversion in PHP so that PHP do not require data type declaration explicitly from one variable to be used.




| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
mod_rewrite - Part 1: create your "fantasy" URL

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting