fork download
  1. <?php
  2.  
  3. $data = [];
  4.  
  5.  
  6. $dat = [
  7. [
  8. "day"=>"wed",
  9. "slots"=>[
  10. [
  11. "start_time"=>"abc",
  12. "end_time"=>"xyz"
  13. ],
  14. [
  15. "start_time"=>"abc",
  16. "end_time"=>"xyz"
  17. ]
  18. ],
  19. "active"=>true
  20. ],
  21. [
  22. "day"=>"tue",
  23. "slots"=>[
  24. [
  25. "start_time"=>"aaa",
  26. "end_time"=>"yyy"
  27. ],
  28. [
  29. "start_time"=>"bbc",
  30. "end_time"=>"xxz"
  31. ]
  32. ],
  33. "active"=>true
  34. ]
  35.  
  36. ];
  37.  
  38. // $data = json_encode($data);
  39. // $data = json_decode($data);
  40.  
  41. $ab = [];
  42. $c = 0;
  43. foreach($dat as $dat){
  44. $c = $c +1;
  45. $i=0;
  46. $data['day'] = $dat['day'];
  47. foreach($dat['slots'] as $slots){
  48.  
  49. $data['slots'][$i] = [
  50. 'start_time' => $slots['start_time'],
  51. 'end_time' => $slots['end_time']
  52. ];
  53. $i=$i+1;
  54. }
  55. $data['active'] = true;
  56. $ab[] = $data;
  57. }
  58.  
  59. echo json_encode($ab);
Success #stdin #stdout 0.02s 26320KB
stdin
Standard input is empty
stdout
[{"day":"wed","slots":[{"start_time":"abc","end_time":"xyz"},{"start_time":"abc","end_time":"xyz"}],"active":true},{"day":"tue","slots":[{"start_time":"aaa","end_time":"yyy"},{"start_time":"bbc","end_time":"xxz"}],"active":true}]