Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing _POST array fully

Tags:

php

I want clear $_POST array content fully, all examples what I see in internet, looks like this:

if (count($_POST) > 0) {     foreach ($_POST as $k=>$v) {         unset($_POST[$k]);     } } 

Tell please, this variant will be not more better? (Point of view as saving resources)

if (count($_POST) > 0) {      $_POST = array(); } 

or not ?

like image 888
Oto Shavadze Avatar asked Oct 18 '12 11:10

Oto Shavadze


1 Answers

Yes, that is fine. $_POST is just another variable, except it has (super)global scope.

$_POST = array(); 

...will be quite enough. The loop is useless. It's probably best to keep it as an array rather than unset it, in case other files are attempting to read it and assuming it is an array.

like image 174
Wesley Murch Avatar answered Oct 09 '22 00:10

Wesley Murch