Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

PHP Data Types

 
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • 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




 
Bartender
Posts: 4568
9
  • 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
MySQL Database PHP Java
  • 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
 
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"
 
I've never won anything before. Not even a tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic