I have two array:
$array_1 = array
(
0 => 12,
1 => 14,
2 => 18
);
$array_2 = array
(
0 => 13,
1 => 14,
2 => 22
);
I need only elements which is present in both array. I've tried array_intersect
but didn't get desired output.
$result = array_intersect($array_1, $array_2);
$result = !empty($result);
print_r($result);
It is giving output 1
instead of 14
.
Your code is perfectly fine.
Just remove the line:
$result = !empty($result);
empty() returns TRUE
or FALSE
only not the actual value of the variable's value.
OR,
Change the above line to:
$result = ! empty($result) ? $result : NULL;