Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PHP Data Types

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They say PHP have buit-in data types like integer,string,float,boolean

but when i try to use it like

integer $a=10;
echo $a;
or
string $a="abc";
echo $a;

None of these works ,then how to use php built in data types




 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has types, but it's a dynamically typed language. Which means that values have types, but the variables don't. So you don't declare the type of variables. So instead, you'd just do:

And notice that it's valid to do both of those: just because a variable has a numeric value doesn't mean you can't then assign it a string value.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for answering the question.

I remember you very well, When i was preparing for my OCJP exam last year.I post a question and you answered it .
So you were the first one "Mathew Brown"

Thank you
 
timo corn
Ranch Hand
Posts: 68
MyEclipse IDE PHP Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
btw you can get the Variable Type with gettype(). Results for the returned string taken from php.net:


"boolean"
"integer"
"double" (for historical reasons "double" is returned in case of a float, and not simply "float")
"string"
"array"
"object"
"resource"
"NULL"
"unknown type"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic