I have the following arrays named investmentprogramscriteria and companyInvestmentProfil:
Array
(
[0] => Array
(
[criteriaID] => 55
[criteriaIsMatchedIf] => 11, 12, 13
)
[1] => Array
(
[criteriaID] => 54
[criteriaIsMatchedIf] => 1
)
[2] => Array
(
[criteriaID] => 52
[criteriaIsMatchedIf] => 1
)
)
Array
(
[0] => Array
(
[criteriaID] => 52
[investmentprofileCriteriaAnswer] => 1
)
[1] => Array
(
[criteriaID] => 54
[investmentprofileCriteriaAnswer] => 1
)
[2] => Array
(
[criteriaID] => 58
[investmentprofileCriteriaAnswer] => 0
)
[3] => Array
(
[criteriaID] => 59
[investmentprofileCriteriaAnswer] => 1
)
[4] => Array
(
[criteriaID] => 55
[investmentprofileCriteriaAnswer] => 1
)
)
I am trying to find out if the value of the criteriaID from the first array (investmentprogramscriteria ) exists in the second array (companyInvestmentProfil) AND IF the value of the key criteriaIsMatchedIf from the first array is equal to the value of the key investmentprofileCriteriaAnswer from the second array.
My current php code returns wrong result at this time:
if (array_intersect($investmentprogramscriteria,$companyInvestmentProfil)) {
echo "Match";
} else {
echo "Not match";
}
array_intersectwill do a string comparison of the values to see if they are the same. Your values are an array, not a string. It won't recursively go through all levels of an array and compare all keys/values to see what is the same.