Lists are called "arrays" in PHP and they're pretty easy to work with:
You can instantiate one just by specifying its members:
$x = array(
array(1, 1, 1),
array(2, 2, 2),
array(3, 3)
);
To append to an array, use empty square brackets:
$x[] = array(4, 4, 4);
To access a particular member, give its key in square brackets:
$x[0]; // array(1, 1, 1)
This works for multidimensional arrays too:
$x[0][2]; // 1
To print out an array so you can see the contents, use print_r
or var_dump
.. though print_r
is neater for arrays.
echo $x; // "Array" .. not great
print_r($x);
/* something like this:
array(
0 => array (
0 => 1
1 => 1
2 => 1
)
1 => array (
.. etc
*/
Arrays can also use strings as the key:
$x['foo'] = 'bar';
These are called "associative arrays".