0% found this document useful (0 votes)
32 views2 pages

08 PHP Variables

The document discusses variables in PHP. It explains that variables are like buckets that store information for use later. There are four basic variable types: boolean, integer, floating point, and string. Boolean variables store true or false values, integers store whole numbers, floating point stores decimal numbers, and strings store text enclosed in quotes.

Uploaded by

REEM Mahdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

08 PHP Variables

The document discusses variables in PHP. It explains that variables are like buckets that store information for use later. There are four basic variable types: boolean, integer, floating point, and string. Boolean variables store true or false values, integers store whole numbers, floating point stores decimal numbers, and strings store text enclosed in quotes.

Uploaded by

REEM Mahdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Lesson 2: Variables

Think of a variable as a bucket. Literally, a bucket. That bucket can hold stuff in it —
like food, or dirt. In PHP, variables are buckets, but instead of holding food or dirt, they
hold information — like numbers, text, images, or logic! All you need to know at this
point is that variables are buckets that store information for later use. We'll get to how
we
actually
use
the
variables in an upcoming lecture.

The basic syntax of a variable is a dollar sign ($) directly followed by a variable name
(using text, with no spaces), then an equal sign, followed by the contents of the
variable, ending with a semi-colon. Ex: $variable_name  =  'my  first  variable';

There are 4 basic variable types, and each type of variable (or "bucket") is meant to
hold specific information.

Boolean
A boolean variable specifies a value of true or false.

1 <?php ?
2        $logged_in  =  true;
3 ?>

Integer
An integer variable is any whole number.

1 <?php ?
2        $fav_num  =  2940;
3 ?>

Floating Point
Usually a fractional number, with a decimal.

1 <?php ?
2        $top_speed  =  104.87;
3 ?>

String
Simple text that must be enclosed within double quotations " " or single quotations ' '

1 <?php ?
2        $vehicle  =  "Subaru";
3 ?>

Previous Lecture Next Lecture

Code
Dynamic
Websites
with
PHP
Copyright ©2014 Brad Hussey of CodeCollege.ca

You might also like