Use array_keys() rather than array_flip(), which fails for NULL values.