PHP Clear all Variables from Above Certain Line

时间:2015-09-14 15:27:07

标签: php arrays string variables optimization

I'm trying to Optimize a Resource Intensive PHP Script for Speed, say I have over 200 variables above it because that's around about correct, when I reach a certain line I want to clear everything from above, is there Anyway of doing this? Would getting the already set variables to an array and unsetting them be the best option or has PHP got a built in function that could handle this?

1 个答案:

答案 0 :(得分:1)

Use scope. When you exit the lower scope, all variables are effectively unset.

Something along these lines:

function doLotsOfStuff() {
    //Use 200 variables, etc.
}

function doMoreStuff() {
    //Do other stuff, not using the above variables, which are no longer stored
}