How to unset multiple variables? [duplicate] How to unset multiple variables? [duplicate] php php

How to unset multiple variables? [duplicate]


try this

unset($foo1, $foo2, $foo3);


Don't use foreach loop for this. Since it works with a copy of array.

See Example

http://codepad.org/mZOc81J5

IF you want to do this using loop then use for loop.


use like this

for($i=0 ; $i<count($array) ; $i++){    unset($array[$i]);}

You have to use for loop for this.

you can use foreach loop but it will not unset all variable one variable still remains.

foreach($array as $arr){    unset($array[$arr]);}