3v4l.org

run code in 300+ PHP versions simultaneously
<?php $resultset = [ ["id" => "1", "cityId" => "1", "cityName" => "Bengaluru", "runId" => "2", "distance" => "10k", "status" => "1"], ["id" => "2", "cityId" => "1", "cityName" => "Bengaluru", "runId" => "1", "distance" => "5k", "status" => "1"], ["id" => "3", "cityId" => "1", "cityName" => "Bengaluru", "runId" => "5", "distance" => "3k", "status" => "0"], ["id" => "4", "cityId" => "2", "cityName" => "Chennai", "runId" => "1", "distance" => "5k", "status" => "1"], ["id" => "5", "cityId" => "2", "cityName" => "Chennai", "runId" => "2", "distance" => "10k", "status" => "1"], ["id" => "6", "cityId" => "2", "cityName" => "Chennai", "runId" => "4", "distance" => "15k", "status" => "1"] ]; foreach ($resultset as $row) { if (!isset($result[$row["cityId"]])) { $result[$row["cityId"]] = array("cityId" => $row["cityId"], $row["cityName"] => array(array("id" => $row["id"])+array_slice($row,-3))); } else { $result[$row['cityId']][$row["cityName"]][] = array("id" => $row["id"])+array_slice($row,-3); } } $result = array("status" => true, "runsBasedOnCity" => array_values($result)); var_export(json_encode($result, JSON_PRETTY_PRINT));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 37
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 37
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
filename:       /in/5fRfJ
function name:  (null)
number of ops:  52
compiled vars:  !0 = $resultset, !1 = $row, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   11     1      > FE_RESET_R                                       $4      !0, ->37
          2    > > FE_FETCH_R                                               $4, !1, ->37
   12     3    >   FETCH_DIM_R                                      ~5      !1, 'cityId'
          4        ISSET_ISEMPTY_DIM_OBJ                         0  ~6      !2, ~5
          5        BOOL_NOT                                         ~7      ~6
          6      > JMPZ                                                     ~7, ->23
   13     7    >   FETCH_DIM_R                                      ~8      !1, 'cityId'
          8        FETCH_DIM_R                                      ~10     !1, 'cityId'
          9        INIT_ARRAY                                       ~11     ~10, 'cityId'
         10        FETCH_DIM_R                                      ~12     !1, 'cityName'
         11        FETCH_DIM_R                                      ~13     !1, 'id'
         12        INIT_ARRAY                                       ~14     ~13, 'id'
         13        INIT_FCALL                                               'array_slice'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 -3
         16        DO_ICALL                                         $15     
         17        ADD                                              ~16     ~14, $15
         18        INIT_ARRAY                                       ~17     ~16
         19        ADD_ARRAY_ELEMENT                                ~11     ~17, ~12
         20        ASSIGN_DIM                                               !2, ~8
         21        OP_DATA                                                  ~11
   12    22      > JMP                                                      ->36
   15    23    >   FETCH_DIM_R                                      ~18     !1, 'cityId'
         24        FETCH_DIM_R                                      ~20     !1, 'cityName'
         25        FETCH_DIM_R                                      ~23     !1, 'id'
         26        INIT_ARRAY                                       ~24     ~23, 'id'
         27        INIT_FCALL                                               'array_slice'
         28        SEND_VAR                                                 !1
         29        SEND_VAL                                                 -3
         30        DO_ICALL                                         $25     
         31        ADD                                              ~26     ~24, $25
         32        FETCH_DIM_W                                      $19     !2, ~18
         33        FETCH_DIM_W                                      $21     $19, ~20
         34        ASSIGN_DIM                                               $21
         35        OP_DATA                                                  ~26
   11    36    > > JMP                                                      ->2
         37    >   FE_FREE                                                  $4
   18    38        INIT_ARRAY                                       ~27     <true>, 'status'
         39        INIT_FCALL                                               'array_values'
         40        SEND_VAR                                                 !2
         41        DO_ICALL                                         $28     
         42        ADD_ARRAY_ELEMENT                                ~27     $28, 'runsBasedOnCity'
         43        ASSIGN                                                   !2, ~27
   20    44        INIT_FCALL                                               'var_export'
         45        INIT_FCALL                                               'json_encode'
         46        SEND_VAR                                                 !2
         47        SEND_VAL                                                 128
         48        DO_ICALL                                         $30     
         49        SEND_VAR                                                 $30
         50        DO_ICALL                                                 
         51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.93 ms | 1008 KiB | 17 Q