fork(1) download
  1. <?php
  2.  
  3. function array_map_associative($callback, $array){
  4. $result = array();
  5. foreach ($array as $key => $value){
  6. $result[] = call_user_func($callback, $key, $value);
  7. }
  8. return $result;
  9. }
  10.  
  11. function callback($key, $value){
  12. return $key . '-' . $value;
  13. }
  14.  
  15. $data = array(
  16. 35 => '3',
  17. 24 => '6',
  18. 72 => '1',
  19. 16 => '5',
  20. 81 => '2',
  21. );
  22.  
  23. $result = implode('|', array_map_associative('callback', $data));
  24.  
  25. var_dump($result);
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
string(24) "35-3|24-6|72-1|16-5|81-2"