V
V
Vladimir Banduristov2019-03-09 18:24:16
PHP
Vladimir Banduristov, 2019-03-09 18:24:16

How to get only exactly matching array elements?

Let's say there are 4 arrays:

array(4) { [0]=> string(1) "1" [1]=> string(1) "2" [1]=> string(1) "3" [2]=> string(1) "4" }
array(3) { [0]=> string(1) "2" [1]=> string(1) "3" [2]=> string(1) "4" }
array(2) { [0]=> string(1) "2" [1]=> string(1) "3" }
array(2) { [0]=> string(1) "2" [1]=> string(1) "3" }

How can I get the value of those array elements that are in all arrays at once (in this example, the value is 2 and 3)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2019-03-09
@vtboren

php.net/manual/ru/function.array-intersect.php
In general, solve the issue as it comes. You understand that writing foreach is simply much easier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question