Search This Blog

Saturday, April 4, 2009

PHP lesson II

Hi all ,
Today we gonna have a look at data types and variable in PHP

is there any data type in php? have you ever noticed that? like other programming languages we don't mention the data type of the variable wehen it declares huh..?
ex..
in C# ig we want an integer variable we declare it like this
int i=0;
but with PHP we dont mention it so. what we do is we simply use
$i=0;

why we can do this, how php going to identify the type of the variable then.. does php has no data type ? we have to find answers fo these questions rite?

the reason for this defference is "typing" what is typing means.. while other laguages use "strong type" php is gonna use "weekly type". basically in a higher level PHP has scalar type only. but behid the screen you can find couple of data type those are integer,string,double. PHP identifies the data type depending on the variable context.. you can see this with the following simple script
$i=10; // this will be integer type
$f=250.00; //this is a double
$str="Hi i'm string"; // this is string type
$s='im too string '; // This is also a string
$c='a'; // This is also a string

/*to see the data type of each variable we can use getType(); function*/

echo( getType($i));
echo "<br/>"; ;

echo(getType($f));
echo "<br/>";

echo( getType($str));
echo "<br/>"; ;

echo( getType($s));
echo "<br/>"; ;

echo(getType($c));
echo "<br/>";

?>

The out put will be like this
integer
double
string
string
string

try this.. hope you got to know something new..
will meet with another lesson later
bye...

:-)

No comments:

Post a Comment