PHP Arrays don't need to be declared with a size.
An array in PHP is actually an ordered map
You also shouldn't get a warning/notice using code like the example you have shown. The common Notice people get is "Undefined offset" when reading from an array.
A way to counter this is to check with isset
or array_key_exists
, or to use a function such as:
function isset_or($array, $key, $default = NULL) {
return isset($array[$key]) ? $array[$key] : $default;
}
So that you can avoid the repeated code.
Note: isset
returns false if the element in the array is NULL, but has a performance gain over array_key_exists
.
If you want to specify an array with a size for performance reasons, look at:
SplFixedArray in the Standard PHP Library.