PHP Function Reference

PHP filter_has_var() Function



The PHP filter_has_var() function checks if variable of specified type exists or not. It returns true on success or false on failure.

Syntax

filter_has_var(input_type, var_name)

Parameters

input_type Required. Specify the input type. It can be one of the following:
  • INPUT_GET
  • INPUT_POST
  • INPUT_COOKIE
  • INPUT_SERVER
  • INPUT_ENV
var_name Required. Specify the variable name to check.

Return Value

Returns true on success or false on failure.

Example: filter_has_var() example

In the example below, filter_has_var() function is used to check if the input variable "email" is sent to the PHP page, through the GET method.

<?php
//checking input variable "email"
if (!filter_has_var(INPUT_GET, "email")) {
  echo("Email not found");
} else {
  echo("Email found");
}
?>

The output of the above code will be:

Email not found

❮ PHP Filter Reference