filter_has_var() function in PHP


The filter_has_var() function is used to check that variable of specified type exists or not.

Syntax

filter_has_var(type, var)

Parameters

  • type − There are five types of inputs to check i.e. INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV.

  • var − The name of variable.

Return

The filter_has_var() function returns true on success and false on failure.

Example

The following is an example that is a quick check for the input variable "email”. The value INPUT_GET is used for this.

 Live Demo

<?php
   if (!filter_has_var(INPUT_GET, "email")) {
      echo("Email isn't there!");
   } else {
      echo("Email is there!");
   }
?>

Output

The following is the output.

Email isn't there!

Updated on: 27-Dec-2019

286 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements