3

I have 2-dimensional GET parameters like request?a[b]=2

I would like to use the php input filter API (http://www.php.net/filter) but cannot find a reasonable way to work on the input a[b].

filter_has_var(INPUT_GET, 'a'); // true

but

filter_has_var(INPUT_GET, 'a[b]'); // false

is there a way to instruct this API to work with 2-dim input parameters ?

Thank you for your help

Jerome

2
  • Why not use the $_GET superglobal? Commented Jul 20, 2011 at 14:15
  • @afuzzyllama: Because it does not tell you if the variable was set by the request or by code. Commented Jul 20, 2011 at 14:33

1 Answer 1

2

a[b] is not a variable name. You can only use filter_has_var with a correct variable name. The variable name for your parameter is a regardless if it is an array or a string.

So you must first check if the get input contains the a parameter and then check it's contents.

$hasVar   = filter_has_var(INPUT_GET, 'a');
$hasArray = $hasVar && is_array($_GET['a']);

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.