Removes elements from an array if they have no corresponding element in another array.

Examples

intersectmyArraywiththetemplateDataofthisstack

Additional Comments

Use the intersect command to filter out elements from an array according to the contents of another array.

Parameters:

The array is any array variable.

The templateArray is any array variable.

Comments:

Each key of the array is checked to see whether there is a matching key in the templateArray. The elements of array that do not match an element of the templateArray are removed from the array.

The content of individual elements of the templateArray does not affect the final result. Only which elements exist in the templateArray, not their content, controls which elements of the array are retained and which are removed. If the array and templateArray have the same set of elements but different content in each element, the intersect command does not change the value of the array.