Variables

To create a variable in php you have to use the dollar sign $


code in php

here you can type some text

Notice that right after the dollar sign $ you type the name of a variable.

Like this $name

$object

$car

$family

$color

$sky


Then you have the equal sign = to assign a value, or something to the variable

$object =

$grass =

$money =

$house =


Then between commas " --- " you put a value to the variable

$object = "big"

$grass = "ghreen"

$money = "34"

$house = "27634"


And then you can just output the variable after the echo, instead of using the actual string of text.


Rules for php variables

No. 1 - A variable starts with the $ sign, followed by the name of the variable

$name = "write something here"

No. 2 - A variable name must start with a letter or the underscore character

$letter = "any letter you want"

$_orThis = "Or the underscore, and you can have two words - or , This"

No. 3 - A variable name cannot start with a number

$3name = "THIS WILL NOT WORK"

No. 4 - A variable name can only have alpha numeric characters and underscores (A-z, 0-9, and _ )

$_InfoJULY_on = "You can do something like this"

No. 5 - Variable names are case-sensitive ($car and $CAR are two different variables)

$car = "This is the variable car"

$CAR = "And this is another variable name CAR, they are different"


Copyright 2017, July, 07