I am trying to count the matches between expected and actual in a PHP array, I have this...
$array = array(
"item" => array(
'expected' => array(
'1' => 25,
'2' => 4,
'3' => 4,
),
'color' => 'red',
'actual' => array(
'1' => 25,
'2' => 4,
'3' => 3,
),
),
);
foreach ($array as $key => $arrayItem) {
$matches = array (
'matches' => count ( array_intersect ( $arrayItem['expected'], $arrayItem['actual'] ) ),
);
}
echo "Matches = " . $matches['matches'];
I am expecting this to return 2 but it is actually returning 3. If I change the values like in the example below then it does work...
$array = array(
"item" => array(
'expected' => array(
'1' => 25,
'2' => 84,
'3' => 4,
),
'color' => 'red',
'actual' => array(
'1' => 25,
'2' => 84,
'3' => 3,
),
),
);
foreach ($array as $key => $arrayItem) {
$matches = array (
'matches' => count ( array_intersect ( $arrayItem['expected'], $arrayItem['actual'] ) ),
);
}
echo "Matches = " . $matches['matches'];
Anyone any ideas why the top version is not giving me the expected result?
4ofexpectedwith 2nd4ofactual.array_intersect: "Returns an array containing all of the values in array1 whose values exist in all of the parameters. "array_intersect_assoc?