fork download
  1. <?php
  2.  
  3. // your code goes here
  4. $response = '{
  5. "Error_spcCode": "0",
  6. "Error_spcMessage": "SUCCESS",
  7. "ListOfStcServiceRequestBo": {
  8. "StcServiceRequestThin": [
  9. {
  10. "INSSub-Area": "Update CPR Expiry Date",
  11. "MSISDN": "97333816947",
  12. "SRNumber": "1-26738240792",
  13. "Status": "Closed",
  14. "STCeSIMActivationCode": null
  15. },
  16. {
  17. "INSSub-Area": "Change SIM Card Request",
  18. "MSISDN": "97333817164",
  19. "SRNumber": "1-26737229064",
  20. "Status": "Closed",
  21. "STCeSIMActivationCode": "LPA:1$consumer.rsp.global$ST2024022012163842D215B5"
  22. },
  23. {
  24. "INSSub-Area": "Change SIM Card Request",
  25. "MSISDN": "97333816947",
  26. "SRNumber": "1-26571086504",
  27. "Status": "Closed",
  28. "STCeSIMActivationCode": "LPA:1$consumer.rsp.global$ST20240220121638AA6EDA40"
  29. },
  30. {
  31. "INSSub-Area": "Change SIM Card Request",
  32. "MSISDN": "97333817164",
  33. "SRNumber": "1-26571016914",
  34. "Status": "Closed",
  35. "STCeSIMActivationCode": "LPA:1$consumer.rsp.global$ST2024022012163842D215B5"
  36. },
  37. {
  38. "INSSub-Area": "Change SIM Card Request",
  39. "MSISDN": "97333817164",
  40. "SRNumber": "1-26571002476",
  41. "Status": "Closed",
  42. "STCeSIMActivationCode": "LPA:1$consumer.rsp.global$ST2024022012163842D215B5"
  43. },
  44. {
  45. "INSSub-Area": "Change SIM Card Request",
  46. "MSISDN": "97333816541",
  47. "SRNumber": "1-26569700194",
  48. "Status": "Closed",
  49. "STCeSIMActivationCode": null
  50. },
  51. {
  52. "INSSub-Area": "Change SIM Card Request",
  53. "MSISDN": "97399009336",
  54. "SRNumber": "1-26568263384",
  55. "Status": "Closed",
  56. "STCeSIMActivationCode": null
  57. },
  58. {
  59. "INSSub-Area": "Change SIM Card Request",
  60. "MSISDN": "97399009336",
  61. "SRNumber": "1-26568230874",
  62. "Status": "Closed",
  63. "STCeSIMActivationCode": null
  64. }
  65. ]
  66. }
  67. }';
  68.  
  69. $response = json_decode($response);
  70.  
  71. if(empty($response->ListOfStcServiceRequestBo->StcServiceRequestThin)) {
  72. $service_requests = [];
  73. }
  74. else {
  75. $service_requests = is_array($response->ListOfStcServiceRequestBo->StcServiceRequestThin) ? $response->ListOfStcServiceRequestBo->StcServiceRequestThin : [$response->ListOfStcServiceRequestBo->StcServiceRequestThin];
  76. }
  77.  
  78. $requests = [];
  79. foreach($service_requests as $service_request) {
  80.  
  81. $requests[] = [
  82. 'msisdn' => substr($service_request->MSISDN, 3),
  83. 'srnumber' => $service_request->SRNumber,
  84. 'status' => $service_request->Status,
  85. 'activationcode' => $service_request->STCeSIMActivationCode,
  86. 'type' => empty($service_request->STCeSIMActivationCode) ? 'Replace SIM': 'Switch to eSIM'
  87. ];
  88. }
  89.  
  90.  
  91. var_dump($requests);
Success #stdin #stdout 0.02s 25532KB
stdin
Standard input is empty
stdout
array(8) {
  [0]=>
  array(5) {
    ["msisdn"]=>
    string(8) "33816947"
    ["srnumber"]=>
    string(13) "1-26738240792"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    NULL
    ["type"]=>
    string(11) "Replace SIM"
  }
  [1]=>
  array(5) {
    ["msisdn"]=>
    string(8) "33817164"
    ["srnumber"]=>
    string(13) "1-26737229064"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    string(50) "LPA:1$consumer.rsp.global$ST2024022012163842D215B5"
    ["type"]=>
    string(14) "Switch to eSIM"
  }
  [2]=>
  array(5) {
    ["msisdn"]=>
    string(8) "33816947"
    ["srnumber"]=>
    string(13) "1-26571086504"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    string(50) "LPA:1$consumer.rsp.global$ST20240220121638AA6EDA40"
    ["type"]=>
    string(14) "Switch to eSIM"
  }
  [3]=>
  array(5) {
    ["msisdn"]=>
    string(8) "33817164"
    ["srnumber"]=>
    string(13) "1-26571016914"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    string(50) "LPA:1$consumer.rsp.global$ST2024022012163842D215B5"
    ["type"]=>
    string(14) "Switch to eSIM"
  }
  [4]=>
  array(5) {
    ["msisdn"]=>
    string(8) "33817164"
    ["srnumber"]=>
    string(13) "1-26571002476"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    string(50) "LPA:1$consumer.rsp.global$ST2024022012163842D215B5"
    ["type"]=>
    string(14) "Switch to eSIM"
  }
  [5]=>
  array(5) {
    ["msisdn"]=>
    string(8) "33816541"
    ["srnumber"]=>
    string(13) "1-26569700194"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    NULL
    ["type"]=>
    string(11) "Replace SIM"
  }
  [6]=>
  array(5) {
    ["msisdn"]=>
    string(8) "99009336"
    ["srnumber"]=>
    string(13) "1-26568263384"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    NULL
    ["type"]=>
    string(11) "Replace SIM"
  }
  [7]=>
  array(5) {
    ["msisdn"]=>
    string(8) "99009336"
    ["srnumber"]=>
    string(13) "1-26568230874"
    ["status"]=>
    string(6) "Closed"
    ["activationcode"]=>
    NULL
    ["type"]=>
    string(11) "Replace SIM"
  }
}