fork(1) download
  1. <?php
  2.  
  3. $arr = [
  4. [
  5. 'COLOR' => 'Red',
  6. 'WEIGHT' => 20
  7. ],
  8.  
  9. [
  10. 'COLOR' => 'Red',
  11. 'WEIGHT' => 25
  12. ],
  13.  
  14. [
  15. 'COLOR' => 'Red',
  16. 'WEIGHT' => 30
  17. ],
  18.  
  19. [
  20. 'COLOR' => 'Green',
  21. 'WEIGHT' => 20
  22. ],
  23.  
  24. [
  25. 'COLOR' => 'Green',
  26. 'WEIGHT' => 25
  27. ],
  28.  
  29. [
  30. 'COLOR' => 'Green',
  31. 'WEIGHT' => 30
  32. ]
  33. ];
  34.  
  35. $out = [];
  36.  
  37. foreach ($arr as $a) {
  38. $out[$a['COLOR']][] = $a['WEIGHT'];
  39. }
  40.  
  41. foreach (array_map(function($a){ return join(', ', $a); }, $out) as $k => $item) {
  42. echo "$k $item\n";
  43. }
Success #stdin #stdout 0.02s 24420KB
stdin
Standard input is empty
stdout
Red 20, 25, 30
Green 20, 25, 30