如何在两个数组中找到共同元素? [关闭]

There are two arrays. It is necessary to display a list from the first array on the page, in which the elements of the second array will be highlighted, for example with a color. Probably it is necessary to read one array in a loop and compare, for example preg_match with the second array and if there is a coincidence - to allocate. Does anyone have a more beautiful solution?

There is an array_intersect function that does pretty much what you need. If you want to compare the elements using regular expressions, try preg_grep, but you will need to prepare the pattern first.