3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = '{ "showElement": "1", "degrees": [{ "Name": "Bachelor in Psychology", "Number": "53", "degree": "Bachelor\'s Degree" }, { "Name": "Certificate", "Number": "56", "degree": "Certificate" }, { "Name": "High School Diploma", "Number": "28", "degree": "High School" }, { "Name": "Bachelor in Sociology", "Number": "109", "degree": "Bachelor\'s Degree" }] }'; $str_arr = json_decode($str); foreach($str_arr->degrees as $k=>$val){ if($val->degree == 'Bachelor\'s Degree'){ $new['Bachelor'][] = $val; }else{ $new[] = $val; } } foreach($new['Bachelor'] as $aa){ $nameStr[]= $aa->Name; $numStr[] = $aa->Number; } $nameStr = implode(', ', $nameStr); $numStr = implode(', ', $numStr); $degree = 'Bachelor\'s Degree'; $new[] = (object) array($nameStr, $numStr, $degree); unset($new['Bachelor']); echo $json = json_encode($new); echo "<pre>"; print_r(json_decode($json));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 16
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 30
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 30
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
Branch analysis from position: 19
filename:       /in/jKJ2W
function name:  (null)
number of ops:  62
compiled vars:  !0 = $str, !1 = $str_arr, !2 = $val, !3 = $k, !4 = $new, !5 = $aa, !6 = $nameStr, !7 = $numStr, !8 = $degree, !9 = $json
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7B%0A+++%22showElement%22%3A+%221%22%2C%0A+++%22degrees%22%3A+%5B%7B%0A+++++++%22Name%22%3A+%22Bachelor+in+Psychology%22%2C%0A+++++++%22Number%22%3A+%2253%22%2C%0A+++++++%22degree%22%3A+%22Bachelor%27s+Degree%22%0A+++%7D%2C+%7B%0A+++++++%22Name%22%3A+%22Certificate%22%2C%0A+++++++%22Number%22%3A+%2256%22%2C%0A+++++++%22degree%22%3A+%22Certificate%22%0A+++%7D%2C+%7B%0A+++++++%22Name%22%3A+%22High+School+Diploma%22%2C%0A+++++++%22Number%22%3A+%2228%22%2C%0A+++++++%22degree%22%3A+%22High+School%22%0A+++%7D%2C+%7B%0A+++++++%22Name%22%3A+%22Bachelor+in+Sociology%22%2C%0A+++++++%22Number%22%3A+%22109%22%2C%0A+++++++%22degree%22%3A+%22Bachelor%27s+Degree%22%0A+++%7D%5D%0A%7D'
   23     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $11     
          4        ASSIGN                                                   !1, $11
   24     5        FETCH_OBJ_R                                      ~13     !1, 'degrees'
          6      > FE_RESET_R                                       $14     ~13, ->19
          7    > > FE_FETCH_R                                       ~15     $14, !2, ->19
          8    >   ASSIGN                                                   !3, ~15
   25     9        FETCH_OBJ_R                                      ~17     !2, 'degree'
         10        IS_EQUAL                                                 ~17, 'Bachelor%27s+Degree'
         11      > JMPZ                                                     ~18, ->16
   26    12    >   FETCH_DIM_W                                      $19     !4, 'Bachelor'
         13        ASSIGN_DIM                                               $19
         14        OP_DATA                                                  !2
   25    15      > JMP                                                      ->18
   28    16    >   ASSIGN_DIM                                               !4
         17        OP_DATA                                                  !2
   24    18    > > JMP                                                      ->7
         19    >   FE_FREE                                                  $14
   32    20        FETCH_DIM_R                                      ~22     !4, 'Bachelor'
         21      > FE_RESET_R                                       $23     ~22, ->30
         22    > > FE_FETCH_R                                               $23, !5, ->30
   33    23    >   FETCH_OBJ_R                                      ~25     !5, 'Name'
         24        ASSIGN_DIM                                               !6
         25        OP_DATA                                                  ~25
   34    26        FETCH_OBJ_R                                      ~27     !5, 'Number'
         27        ASSIGN_DIM                                               !7
         28        OP_DATA                                                  ~27
   32    29      > JMP                                                      ->22
         30    >   FE_FREE                                                  $23
   36    31        INIT_FCALL                                               'implode'
         32        SEND_VAL                                                 '%2C+'
         33        SEND_VAR                                                 !6
         34        DO_ICALL                                         $28     
         35        ASSIGN                                                   !6, $28
   37    36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '%2C+'
         38        SEND_VAR                                                 !7
         39        DO_ICALL                                         $30     
         40        ASSIGN                                                   !7, $30
   38    41        ASSIGN                                                   !8, 'Bachelor%27s+Degree'
   39    42        INIT_ARRAY                                       ~34     !6
         43        ADD_ARRAY_ELEMENT                                ~34     !7
         44        ADD_ARRAY_ELEMENT                                ~34     !8
         45        CAST                                          8  ~35     ~34
         46        ASSIGN_DIM                                               !4
         47        OP_DATA                                                  ~35
   40    48        UNSET_DIM                                                !4, 'Bachelor'
   42    49        INIT_FCALL                                               'json_encode'
         50        SEND_VAR                                                 !4
         51        DO_ICALL                                         $36     
         52        ASSIGN                                           ~37     !9, $36
         53        ECHO                                                     ~37
   43    54        ECHO                                                     '%3Cpre%3E'
         55        INIT_FCALL                                               'print_r'
         56        INIT_FCALL                                               'json_decode'
         57        SEND_VAR                                                 !9
         58        DO_ICALL                                         $38     
         59        SEND_VAR                                                 $38
         60        DO_ICALL                                                 
         61      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.8 ms | 1018 KiB | 17 Q