1

I don't know is there such thing as dynamic array_intersect? Anyway i have 3 arrays ( later there will be much more arrays)

$kaID = array();
$tgID = array();
$ciID = array();

I want to find matching values for all arrays using array_intersect Arrays can be created and filled with values or not. It can be only one populated array OR there can be all three. (later on there will be much more arrays.

How to iterate and create some kind of dynamic expression and get something like this: array_intersect ($kaID, $tgID,$ciID,.... );

4
  • Can you be more specific? array_intersect(...) already take as much array as you want. Commented Sep 8, 2016 at 18:42
  • if you are using php 7 you can also do array_intersect($kaID,...[$tgID,$ciID]) Commented Sep 8, 2016 at 18:46
  • Arrays can be created or not. I dont know final number of arrays Commented Sep 8, 2016 at 20:32
  • Is your question about how to create an array (of arrays) from a list of variables that are each an array, using PHP? i.e. how to convert separate variables $kgID, $tgID ... into an array: array( $kgID, $tgID, ... ) Commented Sep 13, 2016 at 13:36

1 Answer 1

6

You can do something like this:

$collection = [];

//Dynamic
foreach($ids as $id) {
   $collection[] = $id;
}

$result = call_user_func_array('array_intersect', $collection);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.