It feels a little bit around, so I'm going to tell you the problem.
The client form has multiple arrays, such as the item array, an info array, for example:
Now to validate the form, all 4 items must be filled
I encapsulated a function in the background, directly verify that $_request[' ID ' is empty.
But it is troublesome to encounter an array, because of the reason for the function, when the value is passed.
Function Validator ($name) {
Determine if $_request[' $name '] is empty
}
Validator (' id '), so it's better to operate
If not the singular group of the table is OK, the table singular group is very troublesome, need to put the element correct index can
Now I want to ask how the operation can achieve this effect
Validator (' item[' title "] ')
function can be indexed as normal within the
$_request[' item ' [' title ']
Regardless of the array layer, just pass in the correct array element string, you can correctly index the element's table items, cannot find such a function, can only use the method of disassembling the string, do not know there is no better way
It's a good way to get to the unknown item and array index title, of course, this is a 2-layer paradigm, if you can achieve more layers and better
Reply to discussion (solution)
There seems to be no way to implement this by using the array function
Array_walk_recursive should be all right.
The key to the operation after the empty sentence
Array_walk_recursive passed in an array, the key is to pass in the table singular group of elements, the string is mostly
$ar = Array (' item ' = = Array (' title ' + = ', ' intro ' = ') ', ' info ' = = Array (' userid ' = ', ' Userna Me ' + '), function validator ($v, $k) { if (empty ($v)) echo "$k cannot be empty \ n";} Array_walk_recursive ($ar, ' validator ');
Title cannot be empty intro cannot be empty UserID cannot be empty username cannot be empty
Of course, most of the printed content does not meet your requirements.
So I said, "The key is the operation after the empty sentence."
I see, thanks, it's all read and judged.