|
Posted by Ian B on 11/02/05 11:58
Actually, there is only one type of array in PHP and it is really an
ordered map.
PHP maps keys to values and indexes to values.
PHP arrays can appear to behave a little weird if you are used to
'normal' arrays, but they are very flexible once you get the hang of
them. Here are a few things to watch out for:
$stuff=array();
// you now have an empty array
// not usually necessary as simply setting an array member will create
it
$stuff[]="Fred";
// Now your array has one element with an index of 0
$stuff[14]="Bert";
// now your array has 2 elements, indexes 0 and 14
$stuff[] = "Anne";
// 0, 14, 15
$stuff["phone"]="0123456789";
// 0, 14, 15, 16
// but $stuff[16] get you the same thing as $stuff['phone']
// note that there is no $stuff[3] for example.
// trying to use it will cause an error
// also, deleting $stuff[15] will leave you with 0, 14, 16 - the gaps
don't close up
// have a play around - var_dump($stuff) will show you what you have in
the array.
Ian
[Back to original message]
|