fork download
  1. <?php
  2. // your code goes here
  3. $array=array(
  4. 0 => array
  5. (
  6. 'PORAProviderID' => '1010',
  7. 'ProviderName' => 'HAMZEPOUR, SHOKOUFEH',
  8. ),
  9.  
  10. 1 => array
  11. (
  12. 'ContactName' => 'ABC XYZ',
  13. 'Address1' => 'New York',
  14. 'AddressType' => 'Physical'
  15. ),
  16.  
  17. 2 => array
  18. (
  19. 'ContactName' => 'ABC XYZ',
  20. 'Address1' => 'New York',
  21. 'AddressType' => 'Billing'
  22. ),
  23.  
  24. 3 => array
  25. (
  26. 'ContactName' => 'ABC XYZ',
  27. 'Address1' => 'New York',
  28. 'AddressType' => 'Mailing'
  29. ),
  30.  
  31. 4 => array
  32. (
  33. 'AlgorithmID' => 1,
  34. 'AlgoTitle' => 'Retro-Term'
  35. ),
  36.  
  37. 5 => array
  38. (
  39. 'AlgorithmID' => 1,
  40. 'AlgoTitle' => 'Retro-Term'
  41. ),
  42.  
  43. 6 => array
  44. (
  45. 'HoldType' => 'HoldType',
  46. 'StatusID' => 1
  47. ),
  48.  
  49. 7 => array
  50. (
  51. 'HoldType' => 'HoldType',
  52. 'StatusID' => 1
  53. ),
  54. 8 => array
  55. (
  56. 'HoldType' => 'Hold',
  57. 'StatusID' => 2
  58. )
  59.  
  60. );
  61.  
  62. $newArray = array();
  63.  
  64. foreach($array as $arr) {
  65.  
  66. $keys = array_keys($arr);
  67.  
  68. switch($keys[0]) {
  69.  
  70. case "PORAProviderID":
  71.  
  72. if(!isset($newArray["ProviderInfo"])) {
  73. $newArray["ProviderInfo"] = array();
  74. }
  75. $newArray["ProviderInfo"]["PORAProviderID"] = $arr["PORAProviderID"];
  76. $newArray["ProviderInfo"]["ProviderName"] = $arr["ProviderName"];
  77.  
  78. break;
  79.  
  80. case "ContactName":
  81.  
  82. if(!isset($newArray["ProviderAddress"])) {
  83. $newArray["ProviderAddress"] = array();
  84. }
  85. $newArray["ProviderAddress"][$arr['AddressType']] = array();
  86. $newArray["ProviderAddress"][$arr['AddressType']]["ContactName"] = $arr["ContactName"];
  87. $newArray["ProviderAddress"][$arr['AddressType']]["Address1"] = $arr["Address1"];
  88. $newArray["ProviderAddress"][$arr['AddressType']]["AddressType"] = $arr["AddressType"];
  89.  
  90. break;
  91.  
  92. case "AlgorithmID":
  93.  
  94. if(isset($newArray["ProviderAlgorithm"])) {
  95. $count = count($newArray["ProviderAlgorithm"]);
  96. } else {
  97. $newArray["ProviderAlgorithm"] = array();
  98. $count = 0;
  99. }
  100. $newArray["ProviderAlgorithm"][$count] = array();
  101. $newArray["ProviderAlgorithm"][$count]["AlgorithmID"] = $arr["AlgorithmID"];
  102. $newArray["ProviderAlgorithm"][$count]["AlgoTitle"] = $arr["AlgoTitle"];
  103.  
  104. break;
  105.  
  106. case "HoldType":
  107.  
  108. if(isset($newArray["ProviderException"])) {
  109. $count = count($newArray["ProviderException"]);
  110. } else {
  111. $newArray["ProviderException"] = array();
  112. $count = 0;
  113. }
  114. $newArray["ProviderException"][$count] = array();
  115. $newArray["ProviderException"][$count]["HoldType"] = $arr["HoldType"];
  116. $newArray["ProviderException"][$count]["StatusID"] = $arr["StatusID"];
  117.  
  118. break;
  119.  
  120. }
  121.  
  122. }
  123. ?>
  124.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout