How to unset entire array in PHP?

You ought to use: unset ( $err );


Set it to array(), and you should be fine.


$clear = array();
foreach($your_array_variable as $key=>$val){
    $val = '';
    $clear [$key] = $val;
}
print_r($clear);

The below code is to unset same array,

foreach($your_array_variable as $key=>$val){
    $val = '';
    $your_array_variable[$key] = $val;
}
print_r($your_array_variable);

Both of the above code will help you to just unset the values only and won't clear the keys. So keys will be as it is but values will be cleared.

Where it's output will be like below,

array(
[0]=>
[1]=>
)

if you use $your_array_variable = array(); then you will be getting the below output,

Array(
)

Tags:

Php

Arrays