<?php
$number = 1; // set variable $number to 1
$number = $number + 1; // add one to variable $number (=2)
$real = 1.23; // a variable can hold a real number
$price = 11.99;
$total = $number * $price; // set total equal to number times price
$s = "Hello world"; // a variable can hold a string of characters
$a = array(1,2,3); // create an array with three values, 1, 2 and 3
$x = $a[0]; // get the first element from the array (=1)
$x = $a[0] + $a[1] + $a[2]; // add the three elements from the array (=6)
$count = count($a); // set $count equal to the number of elements (=3)
$total = 0; // set the total to 0
for ($i = 0; $i < $count; $i = $i + 1) { // for each element in the array
$element = $a[$i]; // get the ith element from the array
$total = $total + $element; // add the element to the total
}
$average = $total / $count; // set $average equal to the total divided by count
$total = 0; // set total to 0 again
foreach ($a as $element) { // do the same loop with foreach
$total = $total + $element; // add each element to the total
}
$average = $total / $count; // set $average equal to the total divided by count
echo "rating = $average"; // displays: rating = 2
$p = $_REQUEST[p]; // get the p parameter from the query
if ($p == "PS2") { // if it is equal to PS2
echo "platform = $p"; // displays: platform = PS2
}
?>