Certainly nationals of former Spanish colonies, sephardic jews, citizens from the Phillipines, Portugal and Guinea need only 2 years of residence in Spain to be eligible for citizenship. This residence, according to the law, has to be uninterrupted, which means you cannot become a resident of another country meanwhile and then reapply to achieve the period of 2 years.
The Civil Code establishes that the residence situation has to be legal, uninterrupted and prior to the application for nationality. Therefore, any residence situation, as long as it complies with the above requirements, is valid for the purposes of obtaining citizenship.
Let us know if you need more help