Answer the question
In order to leave comments, you need to log in
How to find value repeated in PHP arrays?
Good afternoon! There are, say, 10 arrays. The task is to find values that occur in at least three arrays and add them to a separate array. How it is better to implement it? Thank you!
Answer the question
In order to leave comments, you need to log in
The correct answer is: stop doing nonsense and finally learn how to work with the database.
The literal answer is: any operations on arrays are done using loops .
A little advice: always give the context in which you solve the problem, otherwise you can solve some of your invented problems, and the real problem is solved in a completely different way.
Regarding your question - read the documentation , everything is there:
php > $one = ['red']; $two = ['red', 'green', 'blue']; $three = ['red', 'blue'];
php > var_dump(array_intersect($one, $two, $three));
array(1) {
[0]=>
string(3) "red"
}
//$arrays - исходный список массивов
$count=array();
$new=array();
foreach ($arrays as $a) {
foreach ($a as $key=>$i) {
$count[$key]++;
if ($count[$key]===3) {$new[$key]=$a;}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question