Search code examples
phppostsuperglobals

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


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?


Solution

  • 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';