You should define some variable which would be equal to sub_level_pages[$i] within this loop. Try to dehydrate your code