fork download
  1. <?php
  2.  
  3. $food = [
  4. 1 => 'яблоко',
  5. 2 => 'груша',
  6. 3 => 'арбуз',
  7. 4 => 'морковка',
  8. 5 => 'огуречик',
  9. ];
  10.  
  11. $keys = [4,5];
  12.  
  13. $filtered = array_filter($food, function($food_key) use ($keys) {
  14. return in_array($food_key, $keys);
  15. }, ARRAY_FILTER_USE_KEY);
  16.  
  17. print_r($filtered);
  18.  
Success #stdin #stdout 0.02s 24384KB
stdin
Standard input is empty
stdout
Array
(
    [4] => морковка
    [5] => огуречик
)