3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json_string = '{"error_code":0,"error_message":"","return_data":{"items":[{"id":462,"users":"1,36,38"},{"id":462,"users":"1,4"}]}}'; $res = json_decode($json_string, 1); $items = $res['return_data']['items']; unset($res['return_data']['items']); // unset it first, to replace a new one $new_items = array(); foreach ($items as $key => $item) { $usersArray['id'] = $item['id']; $usersArray['users'] = array(); //create a new Array $usersIdArray = explode(',', $item['users']); foreach ($usersIdArray as $key => $user) { $usersArray['users'][] = array('user_id' => $user); // another level ^ } $res['return_data']['items'][] = $usersArray; } echo json_encode($res, JSON_PRETTY_PRINT);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 40
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 40
Branch analysis from position: 14
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 34
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 34
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 34
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/IiJDY
function name:  (null)
number of ops:  47
compiled vars:  !0 = $json_string, !1 = $res, !2 = $items, !3 = $new_items, !4 = $item, !5 = $key, !6 = $usersArray, !7 = $usersIdArray, !8 = $user
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%22error_code%22%3A0%2C%22error_message%22%3A%22%22%2C%22return_data%22%3A%7B%22items%22%3A%5B%7B%22id%22%3A462%2C%22users%22%3A%221%2C36%2C38%22%7D%2C%7B%22id%22%3A462%2C%22users%22%3A%221%2C4%22%7D%5D%7D%7D'
    4     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 1
          4        DO_ICALL                                         $10     
          5        ASSIGN                                                   !1, $10
    5     6        FETCH_DIM_R                                      ~12     !1, 'return_data'
          7        FETCH_DIM_R                                      ~13     ~12, 'items'
          8        ASSIGN                                                   !2, ~13
    6     9        FETCH_DIM_UNSET                                  $15     !1, 'return_data'
         10        UNSET_DIM                                                $15, 'items'
    7    11        ASSIGN                                                   !3, <array>
    8    12      > FE_RESET_R                                       $17     !2, ->40
         13    > > FE_FETCH_R                                       ~18     $17, !4, ->40
         14    >   ASSIGN                                                   !5, ~18
    9    15        FETCH_DIM_R                                      ~21     !4, 'id'
         16        ASSIGN_DIM                                               !6, 'id'
         17        OP_DATA                                                  ~21
   10    18        ASSIGN_DIM                                               !6, 'users'
         19        OP_DATA                                                  <array>
   11    20        INIT_FCALL                                               'explode'
         21        SEND_VAL                                                 '%2C'
         22        FETCH_DIM_R                                      ~23     !4, 'users'
         23        SEND_VAL                                                 ~23
         24        DO_ICALL                                         $24     
         25        ASSIGN                                                   !7, $24
   12    26      > FE_RESET_R                                       $26     !7, ->34
         27    > > FE_FETCH_R                                       ~27     $26, !8, ->34
         28    >   ASSIGN                                                   !5, ~27
   13    29        INIT_ARRAY                                       ~31     !8, 'user_id'
         30        FETCH_DIM_W                                      $29     !6, 'users'
         31        ASSIGN_DIM                                               $29
         32        OP_DATA                                                  ~31
   12    33      > JMP                                                      ->27
         34    >   FE_FREE                                                  $26
   16    35        FETCH_DIM_W                                      $32     !1, 'return_data'
         36        FETCH_DIM_W                                      $33     $32, 'items'
         37        ASSIGN_DIM                                               $33
         38        OP_DATA                                                  !6
    8    39      > JMP                                                      ->13
         40    >   FE_FREE                                                  $17
   19    41        INIT_FCALL                                               'json_encode'
         42        SEND_VAR                                                 !1
         43        SEND_VAL                                                 128
         44        DO_ICALL                                         $35     
         45        ECHO                                                     $35
         46      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.79 ms | 1444 KiB | 16 Q