PHP Filter_has_var Function

What is filter_has_var() in PHP?

Explanation

filter_has_var() is a function, used to check, whether the variable of the given input method exists or not. This function returns true on success i.e, when the type exists and false on failure.

Syntax:


filter_has_var(type, variable)

In the above syntax, 'type' specifies the input type.
Possible input types are INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER.
'variable' specifies the variable to be checked.

Example :


<?php
if(filter_has_var(INPUT_GET, "name"))
{
echo("Get Method is not empty");
}
else
{
echo("Get Method is empty");
}
?>

Result :

Get Method is not empty

In the above example, the value of "name" is assigned using the url as follows,
test.php?name=hiox
Hence, the output is "Get Method is not empty".

PHP Topics


Ask Questions

Ask Question