Use array_replace instead of manually looping through items