fork download
  1. <?php
  2.  
  3. $str = "1,5";
  4.  
  5. $replacements = explode(',', $str);
  6. $base = array(
  7. 1 => 'Bread',
  8. 2 => 'Gravy',
  9. 3 => 'Stuffing',
  10. 4 => 'Turkey',
  11. 5 => 'Butter',
  12. 6 => 'Squash'
  13. );
  14.  
  15. var_dump(array_intersect_key($base, array_fill_keys($replacements,0)));
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
array(2) {
  [1]=>
  string(5) "Bread"
  [5]=>
  string(6) "Butter"
}