Could you tell me how to index the form array correctly in this example?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.