It's not a secret anymore!
The moose likes PHP and the fly likes PHP Data Types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark "PHP Data Types" Watch "PHP Data Types" New topic

PHP Data Types

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 366

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;
string $a="abc";
echo $a;

None of these works ,then how to use php built in data types , Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Matthew Brown

Joined: Apr 06, 2010
Posts: 4541

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

Joined: Mar 28, 2012
Posts: 366

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

Joined: Oct 26, 2013
Posts: 68

btw you can get the Variable Type with gettype(). Results for the returned string taken from

"double" (for historical reasons "double" is returned in case of a float, and not simply "float")
"unknown type"

I agree. Here's the link:
subject: PHP Data Types
It's not a secret anymore!