fork download
  1. <?php
  2. $source = [
  3. [
  4. 'id' => 10,
  5. 'count' => 1,
  6. ],
  7. [
  8. 'id' => 15,
  9. 'count' => 2,
  10. ],
  11. [
  12. 'id' => 10,
  13. 'count' => 3,
  14. ],
  15. [
  16. 'id' => 12,
  17. 'count' => 4,
  18. ],
  19. [
  20. 'id' => 10,
  21. 'count' => 5,
  22. ],
  23. ];
  24. $output = [];
  25. foreach($source as $arr) {
  26. if (!isset($output[$arr['id']])) $output[$arr['id']] = '';
  27. $output[$arr['id']] .= $arr['count'].',';
  28. }
  29. var_dump($output);
Success #stdin #stdout 0.02s 20568KB
stdin
Standard input is empty
stdout
array(3) {
  [10]=>
  string(6) "1,3,5,"
  [15]=>
  string(2) "2,"
  [12]=>
  string(2) "4,"
}