Understanding PHP arrays

What’s an array?

Simply put an array is a list of items, a lot like FMP repeating fields. Each item is indexed by a number and can contain a variety of different data types. For example, you could have an array with 3 items in it: the first being a number; the second, text; and the third, another array.

Here is a simple 4 element PHP array...

$modes = ('Layout','Browse','Find','Preview');

In PHP the dollar sign is used to identify variables, single or double quotes contain strings, and array values are separated by commas. When you create an array like this, the elements are assigned a numeric index (sometimes called the 'key') starting with zero. So in the example above...

$modes[0] = Layout
$modes[1] = Browse
$modes[2] = Find
$modes[3] = Preview

In PHP you can also assign a name index instead of the internally assigned index, like so...

$modes['design'] = 'Layout';
$modes['data']   = 'Browse';
$modes['search'] = 'Find';
$modes['print']  = 'Preview';

This is called an associative array.

The above is an extremely brief introduction to arrays, but it's all you need to know to start working with PHP and the FX class. For more information see the online documentation.