An offset is undefined if it doesn’t exist in the array. The notice is thrown the first time you reference the element, then PHP initializes the element and sets it to NULL.
To avoid the notice you must initialize the offset. You can test if an offset exists either through array_key_exists or using isset.