This is perhaps a micro-optimization, but array_unshift() is a very slow function.  array_push() and array_pop() are notably faster than shift/unshift.  Or, since it appears that this is being used as a stack, http://us3.php.net/manual/en/class.splstack.php may be even nicer since it pushes more down into the engine where it belongs.