The comment is a clue to their intention, they are resetting the array to an empty one.
If the array already exists, it will be cleared of its current content, but still exist and be ready to receive new values.
If it did not already exist, it will now, an empty array is created, ready to be filled with values.
For another example where this can be used, in clearing sessions, as in a logout.
// User has logged out
session_destroy();
$_SESSION = array();
// session is now clear and contains no values
In the example on that page, $field is an array, choices is a named key in that array. The value of “choices” in $field is an empty array.
This makes $field a multidimensional array, because it contains a nested array as one of its values.
Think of it this way …
the $field variable holds nested arrays. one of these is stored in $field[‘choices’], array() just creates an empty array;
so …
$fields is an (apparently associative) array which holds an array of variables.
‘choices’ is an index in $fields
it also holds an array, which by default holds no elements ( array() ).
this in fact nearly identical to $age[‘Peter’] = “35”;
WHYS DO THIS?
many reasons, among them:
if you didn’t initialize the index with some value it would not exist, by setting the array index to some value or another you prevent errors when you call for that particular index later in the script
to do this you could set it to any value, $field[‘choices’] = ‘’; or $field[‘choices’] = false; or $field[‘choices’] = 0; …etc
however it is likely that the programmer intends that index to always be an array. so by setting $field[‘choices’] = array() you are applying variable typing
this has the benefit that you can now apply any array functions to $field[‘choices’]; using a foreach loop, for example.
at the same time, array() loosely evaluates as false ( much in the away that ‘0’, ‘’, or 0 do) which means you can still test if no values have been inserted into $field[‘choices’] using if ($field[‘choices’]) { do something…}
keeping variable typing in mind, this is also a great way to clear out an existing array in $field[‘choices’] and set the index back to an empty array ( as Sam pointed out this could be inferred from the comments, but those have to be taken in context of the whole scrip,t to be certain)