Variables
1 2 3 4 | $string = "Tennessee" ;
$age = 24;
$double_age = 2 * $age ;
$age_plus_ten = $age + 10;
|
Arrays
1 2 3 4 5 6 7 8 | $items [0] = "orange" ;
$items [1] = "apple" ;
$items [2] = "pear" ;
echo $items [1];
$items [username] = "Joe" ;
$items [school] = "Watkins" ;
|
Conditions (Control Structures)
1 2 3 4 5 6 7 | if ( $age > 20 ) {
echo "you are older than 20" ;
echo " and that is great." ;
}
else {
echo "you are younger than 20" ;
}
|
Functions
1 2 3 4 5 6 7 8 9 10 | $the_year_now = date ( 'Y' );
function year_plus_one() {
$output = 1 + date ( 'Y' );
return $output ;
}
$the_year_plus_one = year_plus_one();
$the_year_plus_two = $the_year_plus_one + 1;
echo $the_year_plus_two ;
|
Loops
1 2 3 4 5 6 7 8 9 10 | for ( $i = 1; $i <=10; $i ++) {
echo ( "the counter is at $i" );
}
$items [username] = "Joe" ;
$items [school] = "Watkins" ;
foreach ( $items as $key => $value ) {
echo ( "For this element, the key is $key and the value is $value." );
}
|