Basics of PHP
Written By: Ryan “boxdain” Macy
- 19 May 2006 -
Description: This intro to PHP covers syntax, variables, operators, condition statements, and an intro to arrays.
Variables
Variables are a way to store data so you don't constantly input data over and over. It will help reduce your workload, but here are a few rules to remember:
- A $ defines a variable
- Variables must start with a letter (a-z) or a underscore ( _ ) they cannot start with numbers.
- Variables may only contain alpha-numeric characters and underscores
- Variables are case sensitive
Here is the syntax of a simple variable:
$A_Variable
You can assign a string to a variable like so:
$A_Variable = "a string";
You can also use the print function as we discussed earlier.
$A_Variable = "a string"; print "$A_Variable = ". $A_Variable;
what you should get:
$A_Variable = a string;
See how easy that was. Now I bet you realizing the potential variables have. Since I have just used a operator ( = ) lets go into detail about them....
Operators
You already have seen an operator (=) which is a assignment operator. Here is a list of the most common operators:
Arithmetic operators
+ is addition
- is subtraction
* is multiplication
/ is division
Comparison operators
== is same as or equal to
!= is not the same or equal to
> is greater than
< is less than
>= is greater than or equal to
<= is less than or equal to
Increment/decrement operators
++ is add one
-- is subtract one
They are really self explanatory so hopefully you got them down pat! Right now lets move onto if else and elseif statements!