A php variable is identied by a leading dollar sign $ in front of the variable.  The variable name can start with either a letter or an underscore _  The name can only contain letters, numbers or underscores.  No spaces.

Assignment statements are used to give variables values i.e.    $name="Linda";

all statements end with a semi-colon ;

String values must be enclosed in quotes.

Variable types do not need to be declared.  The can go from string to numeric to string.

Variables can be inserted into an echo statement i.e.,

echo "my name is $name\n";

To start a new line one need to put a line break in the code before \n  The statement would read:

echo "my name is $name <br/> \n;

Array Variables

Array variables are assigned in an assignment statement with (...) around the values and the word array in front of the (. There is also a comma between each element.  i.e.

$name=array("linda" ,"Peter", "Sean")

Array variables are reference by numbers between brackets [ ] The numbering system starts with 0 This is called a numerical array because it uses numbers to reference the array.

Associative Array uses a string key value to identify the data values.  An example of an associative array of names would be:

$associativename = array("Girl"=> "Linda", "Boy"=>"John");

echo "The Girl is {$associativename["Girl"]} <br />\n";

echo "The Boy is {$associativename ["Boy"]}  <br />\n";

Be sure to put the ending bracket after the ].  So it would be {$...[ ]}

Also do not forget the closing quotes.

Arithmetic codes

+ addition

- subtraction

* multiplication

/ division

%  modulus




Comments (0)