- used to serve a browser, send and receive cookies, build dynamic webpages, evaluate form data
- files must be saved as .php as opposed to .html
- tag:
<?php //text ?> - semi-colon to end lines
- to concatenate elements, use
.(as opposed to+)
$varName = "name";
- $arrayName = array("item0", item1");
- to access elements in the array: $arrayName[0];
- to remove elements:
unset($arrayName[0]);or to remove the whole array:unset($arrayName);
if (value){
//statements
} - for loops:
for ($i=0; $i<10; $i++){
//statements
}- foreach loops: to iterate through each element in an array
foreach ($arrayName as $name){
echo #name;
}- while loops:
while(cond){
//statements
}- dowhile: executes at least once
do{
//statements
}while(cond);echo: output a string, not a functionstrlen("string"): returns the length of the stringsubstr($string, starting position, number of characters to return): returns a substringstrtoupper($string)andstrtolower($string): makes string upper/lower casestrpos($string, "a"): returns position of a letter within the string
round(12.12422, 4): rounds the floating point to 4 digits after decimalrand(1, 10): returns a random number between 1 and 10
array_push($arrayName, element): adds an element to end of arraycount($array): returns the number of elements in the arrayjoin(",", $array): returns the elements with "," in between
function name(parameters){
//statements
}- Creating Classes
class className(parameters){
public $characteristic = parameters;
}-
Creating Instances of Classes
obj1 = new Classname(); -
Accessing Properties
$obj1->property;