fork download
  1. <?php
  2.  
  3. $array1 = array(
  4. '1' => 'a',
  5. '2' => 'b',
  6. '3' => 'c',
  7. '4' => 'd'
  8. );
  9. $string = "1,3|2,3|1,4";
  10. $array2 = explode('|', $string);
  11.  
  12. $foo = '';
  13.  
  14. foreach ($array2 as $items) {
  15. $values = implode(',', array_map(function($i) use ($array1) {
  16. return $array1[$i];
  17. }, explode(',', $items)));
  18. $foo .= "{" . $values . "},";
  19. }
  20.  
  21. echo $foo;
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
{a,c},{b,c},{a,d},