Tuesday, June 2, 2009

PHP - Array

An array is a data structure that stores one or more values in a single value.

Structure of an array
$employee_array[0] = "Hung";
$employee_array[1] = "Thao";
$employee_array[2] = "Thang";
$employee_array[3] = "Hoa";
The general form for setting the key of an array equal to a value is:
  • $array[key] = value;
Note: As you may have noticed from the above code example, an array's keys start from 0 and not 1.

Display content:

echo "Two of my employees are "
. $employee_array[0] . " & " . $employee_array[1];
echo "
Two more employees of mine are "

. $employee_array[2] . " & " . $employee_array[3];