I have an array of array data from $ search and $ data strong>, like this:
$data = array(
array(1, 2, 3),
array(1, 2, 3, 4, 7, 13)
);
$search = array(
array(1, 2),
array(1, 3),
array(6, 13),
array(7, 13)
);
$result = array();
I want each pair (example: 1 and 2) of array data from $ search to match all the data inside the $ data strong> variable , it will calculate how much data matches (EXAMPLE: 1 and 2 have a match for $ data [0 ] and $ data [1] , so the result should be 2). And then save the result of the calculation in the variable $ result based on the key from $ search .
Here is the result I was looking for:
$result = array(
0 => 2,
1 => 2,
2 => 0
3 => 1
);
And this is my code:
for ($i=0; $i<count($search); $i++) {
for ($j=0; $j<count($data); $j++) {
if (count(array_intersect($search[$i], $data[$j])) > 1) {
array_push($result[$i], "1");
}
}
}
, $result, : array_push() , 1 . array_push $search, :
Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 1
[3] => 1
)
[1] => Array
(
[0] => 1
[1] => 3
[2] => 1
[3] => 1
)
[2] => Array
(
[0] => 6
[1] => 13
)
[3] => Array
(
[0] => 7
[1] => 13
[2] => 1
)
)
, , , . , .