fork download
  1. <?php
  2. $str = "1,5";
  3. $replacements = explode(',', $str);
  4. $base = array('1'=>'Bread','5'=>'Butter');
  5.  
  6. $basket = array_map(function($a) use($base){
  7. return $base[$a];
  8. }, $replacements);
  9.  
  10. print_r($basket);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Bread
    [1] => Butter
)