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("id" => $row["id"], "cityId" => $row["cityId"], $row["cityName"] => array(array_slice($row,-3))); } else { $result[$row['cityId']][$row["cityName"]][] = 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 = 33
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 33
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/f6Ecq
function name:  (null)
number of ops:  48
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, ->33
          2    > > FE_FETCH_R                                               $4, !1, ->33
   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, ->22
   13     7    >   FETCH_DIM_R                                      ~8      !1, 'cityId'
          8        FETCH_DIM_R                                      ~10     !1, 'id'
          9        INIT_ARRAY                                       ~11     ~10, 'id'
         10        FETCH_DIM_R                                      ~12     !1, 'cityId'
         11        ADD_ARRAY_ELEMENT                                ~11     ~12, 'cityId'
         12        FETCH_DIM_R                                      ~13     !1, 'cityName'
         13        INIT_FCALL                                               'array_slice'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 -3
         16        DO_ICALL                                         $14     
         17        INIT_ARRAY                                       ~15     $14
         18        ADD_ARRAY_ELEMENT                                ~11     ~15, ~13
         19        ASSIGN_DIM                                               !2, ~8
         20        OP_DATA                                                  ~11
   12    21      > JMP                                                      ->32
   15    22    >   FETCH_DIM_R                                      ~16     !1, 'cityId'
         23        FETCH_DIM_R                                      ~18     !1, 'cityName'
         24        INIT_FCALL                                               'array_slice'
         25        SEND_VAR                                                 !1
         26        SEND_VAL                                                 -3
         27        DO_ICALL                                         $21     
         28        FETCH_DIM_W                                      $17     !2, ~16
         29        FETCH_DIM_W                                      $19     $17, ~18
         30        ASSIGN_DIM                                               $19
         31        OP_DATA                                                  $21
   11    32    > > JMP                                                      ->2
         33    >   FE_FREE                                                  $4
   18    34        INIT_ARRAY                                       ~22     <true>, 'status'
         35        INIT_FCALL                                               'array_values'
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                         $23     
         38        ADD_ARRAY_ELEMENT                                ~22     $23, 'runsBasedOnCity'
         39        ASSIGN                                                   !2, ~22
   20    40        INIT_FCALL                                               'var_export'
         41        INIT_FCALL                                               'json_encode'
         42        SEND_VAR                                                 !2
         43        SEND_VAL                                                 128
         44        DO_ICALL                                         $25     
         45        SEND_VAR                                                 $25
         46        DO_ICALL                                                 
         47      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.68 ms | 1008 KiB | 17 Q