php - use of filter_input_array and array_filter on the same array -



php - use of filter_input_array and array_filter on the same array -

i have variable set of identical input fields in form can empty.

<input type="text" class="form-control" name="option[]" placeholder="fill in" /> <input type="text" class="form-control" name="option[]" placeholder="optional" /> <input type="text" class="form-control" name="option[]" placeholder="optional" />

the values of these input fields come array $_post["option"]

i want filter $_post["option"] , using next code:

$filter = array("option" => array("filter"=>filter_callback,"flags"=>filter_force_array,"options"=>"ucwords")); $optionfin = filter_input_array(input_post, $filter);

but want utilize array_filter function remove empty fields can input filled in fields database doesn't seem work.

$option = array_filter($optionfin);

when following:

$optionfin = array_filter($_post["option"]);

this working fine, know improve not access $_post way because isn't safe...

can help me point out going wrong?

thanks

because using filter_input_array, end associative array corresponds $_post. filter out empty fields trying do, need specify option key:

$option = array_filter($optionfin['option']);

php arrays

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -