Variables in PHP

Variables are represented by a $ followed by the variable name. Variable names are case sensitive.

Echo variable to screen:

Hello World

Print to screen:

Hello to you

Variable Substituion:

I won £10

Variable Substituion with braces:

I won £15
I won £{$myVar} - single quotes variable NOT substituted
I won £15
I won £{$myVar} - single quotes variable NOT substituted

Recommend braces { ....... } for variables placed in string literals. Use double quotes here. Single quoted string literas will not be substituted.

My name is Martin

Using printf()

Use printf() can be followed by one or more parameters

I have won 5.23 Pounds

Concatenation

p>Concatenation using the period/dot (.) character

Martin Cooper

Boolean Variables (1 = true, 0 = false)

1

Integer Variables

10

Float Variables

1.55
1.6
56,000
1.25

String Variables

one man went to sow

Constants

Once set can't be changed - no need for a dollor by convention use UPPERCASE name.

0.75

Data Casting

Hello 5 3.4 1