3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = '{ "data": { "id": 2, "title": "second evaluation form", "emp_position": "System Architecture", "rating": 5, "segments": [ { "segment_name": "Job Role ", "question": "How old are you?" }, { "segment_name": "360 Segments", "question": "What is your food?" }, { "segment_name": "360 Segments", "question": "sample question" } ] } }'; $data = json_decode($json,true); $segments = $data['data']['segments']; $new_segemnts = array(); foreach($segments as $segemnt) { $key = $segemnt['segment_name']; $new_segemnts[$key]['segment_name']=$segemnt['segment_name']; $new_segemnts[$key]['question_collection'][]=array("question"=>$segemnt['question']); } $data['data']['segments'] = array_values($new_segemnts); echo json_encode($data,JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 25
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 25
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/0YGEh
function name:  (null)
number of ops:  38
compiled vars:  !0 = $json, !1 = $data, !2 = $segments, !3 = $new_segemnts, !4 = $segemnt, !5 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%7B%0A++++++++%22data%22%3A+%7B%0A++++++++++++%22id%22%3A+2%2C%0A++++++++++++%22title%22%3A+%22second+evaluation+form%22%2C%0A++++++++++++%22emp_position%22%3A+%22System+Architecture%22%2C%0A++++++++++++%22rating%22%3A+5%2C%0A++++++++++++%22segments%22%3A+%5B%0A++++++++++++++++%7B%0A++++++++++++++++++++%22segment_name%22%3A+%22Job+Role+%22%2C%0A++++++++++++++++++++%22question%22%3A+%22How+old+are+you%3F%22%0A++++++++++++++++%7D%2C%0A++++++++++++++++%7B%0A++++++++++++++++++++%22segment_name%22%3A+%22360+Segments%22%2C%0A++++++++++++++++++++%22question%22%3A+%22What+is+your+food%3F%22%0A++++++++++++++++%7D%2C%0A++++++++++++++++%7B%0A++++++++++++++++++++%22segment_name%22%3A+%22360+Segments%22%2C%0A++++++++++++++++++++%22question%22%3A+%22sample+question%22%0A++++++++++++++++%7D%0A++++++++++++%5D%0A++++++++%7D%0A++++%7D'
   26     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     <true>
          4        DO_ICALL                                             $7      
          5        ASSIGN                                                       !1, $7
   29     6        FETCH_DIM_R                                          ~9      !1, 'data'
          7        FETCH_DIM_R                                          ~10     ~9, 'segments'
          8        ASSIGN                                                       !2, ~10
   30     9        ASSIGN                                                       !3, <array>
   31    10      > FE_RESET_R                                           $13     !2, ->25
         11    > > FE_FETCH_R                                                   $13, !4, ->25
   33    12    >   FETCH_DIM_R                                          ~14     !4, 'segment_name'
         13        ASSIGN                                                       !5, ~14
   35    14        FETCH_DIM_R                                          ~18     !4, 'segment_name'
         15        FETCH_DIM_W                                          $16     !3, !5
         16        ASSIGN_DIM                                                   $16, 'segment_name'
         17        OP_DATA                                                      ~18
   36    18        FETCH_DIM_R                                          ~22     !4, 'question'
         19        INIT_ARRAY                                           ~23     ~22, 'question'
         20        FETCH_DIM_W                                          $19     !3, !5
         21        FETCH_DIM_W                                          $20     $19, 'question_collection'
         22        ASSIGN_DIM                                                   $20
         23        OP_DATA                                                      ~23
   31    24      > JMP                                                          ->11
         25    >   FE_FREE                                                      $13
   39    26        INIT_FCALL                                                   'array_values'
         27        SEND_VAR                                                     !3
         28        DO_ICALL                                             $26     
         29        FETCH_DIM_W                                          $24     !1, 'data'
         30        ASSIGN_DIM                                                   $24, 'segments'
         31        OP_DATA                                                      $26
   40    32        INIT_FCALL                                                   'json_encode'
         33        SEND_VAR                                                     !1
         34        SEND_VAL                                                     128
         35        DO_ICALL                                             $27     
         36        ECHO                                                         $27
         37      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.89 ms | 2852 KiB | 15 Q