fork(1) download
  1. <?php
  2.  
  3. $periods = array(
  4. 201308,
  5. 201309,
  6. 201310
  7. );
  8.  
  9. $groupExport = array(
  10. 'GroupCode' => 111,
  11. 'GroupDesc' => 'Crop Production',
  12. '201308' => 1.5500,
  13. '201309' => 240.4200,
  14. '201310' => 41.2110
  15. ),
  16.  
  17. 'GroupCode' => 112,
  18. 'GroupDesc' => 'Animal Production',
  19. '201309' => 3.1800
  20. ),
  21.  
  22. 'GroupCode' => 115,
  23. 'GroupDesc' => 'Agriculture, Forestry Support',
  24. '201308' => 234.0400,
  25. '201310' => 343.0200
  26. )
  27. );
  28.  
  29. $keys = array_fill_keys($periods, 0);
  30. array_walk($groupExport, function (&$item, $key, $keys) {
  31. $item += $keys;
  32. }, $keys);
  33.  
  34. ksort($groupExport);
  35.  
  36. print_r($groupExport);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [GroupCode] => 111
            [GroupDesc] => Crop Production
            [201308] => 1.55
            [201309] => 240.42
            [201310] => 41.211
        )

    [1] => Array
        (
            [GroupCode] => 112
            [GroupDesc] => Animal Production
            [201309] => 3.18
            [201308] => 0
            [201310] => 0
        )

    [2] => Array
        (
            [GroupCode] => 115
            [GroupDesc] => Agriculture, Forestry Support
            [201308] => 234.04
            [201310] => 343.02
            [201309] => 0
        )

)