There are two arrays. It is necessary to leave with the first array only those elements that are found in the second. As you know, you can do this with in_array
inside foreach
:
$firstArray = array('A','B','C','D','E'); $secondArray = array('A','C','E','X','Y','Z'); $arrayOfResults = array(); foreach($firstArray as $item) { if(in_array($arrayOfAllItems, $secondArray )) { $arrayOfResults[] = $item; } } echo implode(',',$arrayOfResults); // A, C, E
But how can I get $arrayOfResults
without using foreach()
? For example via array_map()
or something else?
foreach
? - Dmitriy Simushev