how to check multiple $_POST variable for existence using isset()?

PHP picture PHP · Jun 19, 2013 · Viewed 17.1k times · Source

I need to check if $_POST variables exist using single statement isset.

if (isset$_POST['name']  &&  isset$_POST['number']  &&  isset$_POST['address']  &&  etc ....)

is there any easy way to achieve this?

Answer

sectus picture sectus · Jun 19, 2013

Use simple way with array_diff and array_keys

$check_array = array('key1', 'key2', 'key3');
if (!array_diff($check_array, array_keys($_POST)))
    echo 'all exists';