There are two arrays:

$paramsCatID = array( '0'=> '1', '1'=> '2', '2'=> '3', ); $allCatID = array( '0'=> array ('category_id'=>"1"), '1'=> array ('category_id'=>"2"), '2'=> array ('category_id'=>"3"), '3'=> array ('category_id'=>"4"), '4'=> array ('category_id'=>"5"), '5'=> array ('category_id'=>"6"), '6'=> array ('category_id'=>"7"), ); 

How can I output the values ​​from the second array $allCatID knowing the values ​​in the first array $paramsCatID .

That is, should be brought out:

  $allCatID = array( '0'=> array ('category_id'=>"1"), '1'=> array ('category_id'=>"2"), '2'=> array ('category_id'=>"3"), ); 
  • loop through the second array with checking in_array in the first - splash58
  • You can translate an example, but something that my brain doesn’t understand how to write. I don’t understand the convolutions, but it’s impossible to write ... - Oleg Kosarev

2 answers 2

 foreach($allCatID as $key=>$arr){ foreach($arr as $categoryId=>$value){ if (in_array($value,$paramsCatID)){ print_r($allCatID[$key][$categoryId]); } } } 
     print_r(array_map(function($i) { return array('category_id'=>$i); }, array_intersect( array_map(function($i) {return $i['category_id']; }, $allCatID), $paramsCatID)));