I would like to explain how to index the form array correctly in this example.
The client form has multiple arrays, such as the item array and info array. for example:
To verify the form, all four items are required
I encapsulated a function in the background to directly verify that $ _ REQUEST ['id'] is null.
However, it is very troublesome to use arrays. this is the case when values are passed due to function reasons.
Function validator ($ name ){
Judge whether $ _ REQUEST ['$ name'] is null
}
Validator ('id ').
If the form array is not good, the form array is very troublesome. you need to index the elements correctly.
Now I want to ask how the operation can achieve this effect.
Validator ('item ["title"] ')
The normal index in the function is
$ _ REQUEST ['item'] ['title']
No matter the number of layers in the array, if you pass in the correct array element string, you can correctly index the form items of the element. if you cannot find such a function, you can only disassemble the string, I wonder if there is any better way.
To put it bluntly, it is how to correctly obtain the unknown item and array index title. of course, this is a two-layer example. if more layers can be implemented, better
Reply to discussion (solution)
It seems that there is no way to implement this through the array function
Array_walk_recursive should be enough.
Key operations after and after empty criteria
Array_walk_recursive is used to input arrays. The key is to input elements in the form array, with many strings.
$ Ar = array ('item' => array ('title' => '', 'Intro' => ''), 'info' => array ('userid' => '', 'username' =>''),); function validator ($ v, $ k) {if (empty ($ v) echo "$ k cannot be blank \ n";} array_walk_recursive ($ ar, 'validator ');
Title cannot be blank intro cannot be blank userid cannot be blank username cannot be blank
Of course, most of the printed content does not meet your requirements.
So I said, "The key lies in the operation after being empty"
Thank you. read all the results.