PHP Dynamic Parameters

Source: Internet
Author: User
$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'                    );

Now the problem is, I don't know how many arrays there are in $result, there may be a-d, there may only be a and d.

The Array_intersect_ukey function is also dynamically based on this dynamic incoming parameter.
For example, only A and D

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

Like only A,c and D.

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

How do you implement this dynamic incoming parameter? Or is there any other way to implement it?

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'                    );

Now the problem is, I don't know how many arrays there are in $result, there may be a-d, there may only be a and d.

The Array_intersect_ukey function is also dynamically based on this dynamic incoming parameter.
For example, only A and D

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

Like only A,c and D.

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

How do you implement this dynamic incoming parameter? Or is there any other way to implement it?

I did not take a closer look at the landlord's question, but I told the landlord two points, I am sure is able to solve the problem described by the landlord:

1. Take note of 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 mention it:
Func_num_args (); Number of output parameters
Func_get_args; Get parameter, return parameter array
3. Since the number of parameters and the name is not determined, then, you can pass the 1 function to a function to pass parameters, remember the parameter array way, array can let you pass various parameters

Landlord of the problem, should be able to solve.

Back and carefully looked at the landlord's question, yes, Call_user_func_array can be to help you.

Can be called recursively or cyclically.

The A ∩ B ∩ C = ( A ∩ B ) ∩ C intersection of the first two arrays is computed, and then the intersection is computed with the result of the first calculation and the third array (if any), and so on.

I've asked a similar question before, 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.