loading
I am available for new opportunities
logo

Hi, I'mGlen Taylor

Download Resume

Checking for Multiple $_POST Variables – PHP

I just stumbled across this fantastic snippet of code for check for the existence of multiple variables with the global $_POST.

Previously I would have check the variables by stinging together multiple isset functions like so.

if (isset($_POST['key1']) && isset($_POST['key2']) && isset($_POST['key3'])) { //do something here }

However, the new snippet I recently found is great for accomplishing this check in a much more efficient way.

$check_post = array('key1', 'key2', 'key3');
if (!array_diff($check_post, array_keys($_POST))) {
     //do something here
}

This will really make checking for the existence of POST variables much easier.

Cheers!

  • Share this :

Leave a comment