Keep only value present in both Array PHP
arrays, php
Solution
Use `array_intersect()`:
$array3 = array_intersect( $array1, $array2);
If you want to get rid of the keys, run that array through `array_values()`:
$array3 = array_values( $array3);
This will set `$array3` to:
Array
(
[0] => 10
[1] => 15
)
Problem
I have two array, let's say ``` $array1 = array(0 => 10, 1 => 21, 2 => 34, 'somekey' => 45, 'otherkey' => 15); $array2 = array(0 => 9, 1 => 10, 2 => 14, 'otherkey' => 15, 'somekey' => 43); ``` I need to return an array with only the values contained by both arrays, independent of their keys. In this case, the resulting array would contain value 10 at key 0, value 15 at key 1