I have two arrays $t1 and $t2. When I print them out I get the following:
t1:
Array ( [0] => Christina Aguilera [1] => Iron Maiden [2] => Bob Marley )
t2:
Array ( [0] => Bob Marley )
I'm trying to get the common elements of the array though the array_intersect function, and I'm using the below line:
$intersection = array_intersect($t1,$t2);
However, for some reason when I print the result $intersection I get get:
Array ( )
Can anybody see what it is going wrong? The code for my function is below but I think the above should be sufficient to work it out.
// For extra information
function findMutualInterests($_uProArray, $_tProArray)
{
$_commonDetails = null;
$_fieldNames = array_keys($_uProArray[0]);
$_uProValues = array_values($_uProArray[0]);
$_tProValues = array_values($_tProArray[0]);
//print_r($_uProValues);
// Iterate over the arrays and find ones in common
for ($i = 0; $i < count($_uProValues); $i++) {
$t1 = explode(',',$_uProValues[$i]);
print_r($t1);
$t2 = explode(',',$_tProValues[$i]);
print_r($t2);
$intersection = array_intersect($t1,$t2);
print_r($intersection);
$_commonDetails[$_fieldNames[$i]] = implode($intersection);
}
return $_commonDetails;
}
EDIT: Just thought I would point out that the output of $t1 and $t2 shown above are the output of a single iteration of the below function. I just chose that one as an example.
trim()before inserting the values in the arrays?var_dump($intersection)?var_dumpshows the type and length of all variables.var_dump($t1);andvar_dump($t2);