Fix error: undefined offset 0 in array