array_pop/array_shift optimization