PHP Dynamic Parameters

Source: Internet
Author: User
The problem with {code...} is that I don't know how many arrays exist in $ result, maybe a-d, maybe a and d. Then the array_intersect_ukey function must dynamically input parameters based on the dynamic parameters. For example, there is only a and d {code...}, for example, how to implement only a, c, and d {code...
$result = [    'a'=>[1,2],    'b'=>[1,2],    'c'=>[1,2],    'd'=>[1,2],]array_intersect_ukey(                    $result['a'],                    $result['b'],                    $result['c'],                    $result['d'],                    'test'                    );

The problem is that I don't know the number of arrays in the $ result, maybe a-d, maybe a and d.

Then the array_intersect_ukey function must dynamically input parameters based on the dynamic parameters.
For example, only a and d

array_intersect_ukey(                    $result['a'],                    $result['d'],                    'test'                    );

For example, only a, c, and d

array_intersect_ukey(                    $result['a'],                    $result['c'],                    $result['d'],                    'test'                    );

How can we implement this dynamic input parameter? Or is there any other implementation method?

Reply content:
$result = [    'a'=>[1,2],    'b'=>[1,2],    'c'=>[1,2],    'd'=>[1,2],]array_intersect_ukey(                    $result['a'],                    $result['b'],                    $result['c'],                    $result['d'],                    'test'                    );

The problem is that I don't know the number of arrays in the $ result, maybe a-d, maybe a and d.

Then the array_intersect_ukey function must dynamically input parameters based on the dynamic parameters.
For example, only a and d

array_intersect_ukey(                    $result['a'],                    $result['d'],                    'test'                    );

For example, only a, c, and d

array_intersect_ukey(                    $result['a'],                    $result['c'],                    $result['d'],                    'test'                    );

How can we implement this dynamic input parameter? Or is there any other implementation method?

I did not elaborate on the problem of the landlord, but I told the landlord two points that I could certainly solve the problem described by the landlord:

1. Pay attention to a function called call_user_func_array ().
Http://php.net/manual/zh/function.call-user-func-array.php
2. This may not be as important as 1, but I 'd like to mention it:
Func_num_args (); // number of output parameters
Func_get_args; // gets the parameter and returns an array of parameters.
3. Since the number of parameters and the name are not sure, you can pass the parameter to a function through the function in 1. Remember that the parameter uses the array method, and the array allows you to pass various parameters.

The landlord's problem should be solved.

Back, I took a closer look at the problem of the landlord. That's right. call_user_func_array can help you.

It can be called recursively or cyclically.

AccordingA ∩ B ∩ C = ( A ∩ B ) ∩ CThe first time you calculate the intersection of the first two arrays, then use the result of the first calculation and the third array (if any) to calculate the intersection, and so on.

I used to ask a similar question https://segmentfault.com/q/1010000004290664

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.