-
array() is a blank array and you can use this to set the variable as an array before you do anything. But you can also just use $var[] to set the "next" (starting at 0) part of the array.
One reason for force $var=array(); at the start is that if you don't it's possible to have conflicts of variable type, like if for some reason the system assumes you're working with a string. But in general the important thing is the way in which you store data to the variable.
It's similar to:
PHP Code:
$var = ''; //set a a blank string [establish type]
$var = 'Hello World'; //set a value to the string
Of course it's not particularly useful in that case, but that's about the same as using array(); to start an array.
In some cases, array() can be useful, such as if you might get no results but want it to still evaluate true when using is_array() or you want to use it in a foreach loop:
PHP Code:
$var = array();
while (something) {
$var[] = something;
}
foreach($var as $v) {
echo $v;
}
array() establishes it as an array with no values-- it can act like an array in foreach. Now if you DO have data entered into it from t he while loop then it'll be like normal. But if you DON'T then it won't give you an error trying to send a non-existing array through the foreach loop. This happens a lot with databases, for example. You may get no results when you search, so first setting it as a blank array helps avoid problems.