3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 'q0data' => '{"question":"chicken","modal":"ought to","probability":"high","utilitygain":"low","subcondition":"Edward","rt":2975,"response":"agree","freeResponse":"wvwvwewe"}', 'q1data' => '{"question":"procrastinate","modal":"ought to","probability":"low","utilitygain":"high","subcondition":"accept","rt":2603,"response":"disagree","freeResponse":"vwevewvewvewvew"}', 'language' => 'vewoievwnpio', 'payment' => 'ceeqqecqeq' ); function parseTrialData ($trialData) { $trialData = substr($trialData, 1, -1); // get rid of leading '{' and trailing '}' $trialData = explode(',', $trialData); // 'explode' is PHP for 'split' // i.e., separate the string into an array of strings of form 'key:value' $parsedTrialData = array(); foreach ($trialData as $kv) { $exploded = explode(':', $kv); $parsedTrialData[$exploded[0]] = $exploded[1]; } return $parsedTrialData; } $headerItems = array(); $trialData = array(); foreach (array_keys($arr) as $key) { $value = $arr[$key]; if (mb_substr($value, 0, 1) == '{' and mb_substr($value, strlen($value) - 1, 1) == '}') { // if the data starts and ends with '{', '}' then it's a complex data object representing a single trial. // so, add the key-value pair to $trialData array to await further processing $trialData[$key] = $value; } else { // otherwise, it's data shared across all trials; so add the pair to the $headerItems array $headerItems[$key] = $value; } } $header = ""; // for new files, make header showing variable names $globalHeader = ""; foreach (array_keys($headerItems) as $key) { $globalHeader .= $key . ","; } $localHeader = ""; if (count($trialData) !== 0) { $parsedSampleTrialData = parseTrialData(array_values($trialData)[0]); foreach (array_keys($parsedSampleTrialData) as $key) { $localHeader .= substr($key, 1, -1) . ","; } } $header .= $globalHeader . $localHeader; $header = substr($header, 0, -1) . "\n"; foreach (array_values($trialData) as $trialStr) { echo $trialStr . "\n"; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 33
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 30
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 26
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 44
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 44
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 71
Branch analysis from position: 49
2 jumps found. (Code = 77) Position 1 = 61, Position 2 = 70
Branch analysis from position: 61
2 jumps found. (Code = 78) Position 1 = 62, Position 2 = 70
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 70
2 jumps found. (Code = 77) Position 1 = 84, Position 2 = 88
Branch analysis from position: 84
2 jumps found. (Code = 78) Position 1 = 85, Position 2 = 88
Branch analysis from position: 85
1 jumps found. (Code = 42) Position 1 = 84
Branch analysis from position: 84
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 88
Branch analysis from position: 70
Branch analysis from position: 71
Branch analysis from position: 44
Branch analysis from position: 33
filename:       /in/GVUcU
function name:  (null)
number of ops:  90
compiled vars:  !0 = $arr, !1 = $headerItems, !2 = $trialData, !3 = $key, !4 = $value, !5 = $header, !6 = $globalHeader, !7 = $localHeader, !8 = $parsedSampleTrialData, !9 = $trialStr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   23     1        ASSIGN                                                   !1, <array>
   24     2        ASSIGN                                                   !2, <array>
   26     3        INIT_FCALL                                               'array_keys'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $13     
          6      > FE_RESET_R                                       $14     $13, ->33
          7    > > FE_FETCH_R                                               $14, !3, ->33
   27     8    >   FETCH_DIM_R                                      ~15     !0, !3
          9        ASSIGN                                                   !4, ~15
   28    10        INIT_FCALL                                               'mb_substr'
         11        SEND_VAR                                                 !4
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 1
         14        DO_ICALL                                         $17     
         15        IS_EQUAL                                         ~18     $17, '%7B'
         16      > JMPZ_EX                                          ~18     ~18, ->26
         17    >   INIT_FCALL                                               'mb_substr'
         18        SEND_VAR                                                 !4
         19        STRLEN                                           ~19     !4
         20        SUB                                              ~20     ~19, 1
         21        SEND_VAL                                                 ~20
         22        SEND_VAL                                                 1
         23        DO_ICALL                                         $21     
         24        IS_EQUAL                                         ~22     $21, '%7D'
         25        BOOL                                             ~18     ~22
         26    > > JMPZ                                                     ~18, ->30
   31    27    >   ASSIGN_DIM                                               !2, !3
         28        OP_DATA                                                  !4
         29      > JMP                                                      ->32
   34    30    >   ASSIGN_DIM                                               !1, !3
         31        OP_DATA                                                  !4
   26    32    > > JMP                                                      ->7
         33    >   FE_FREE                                                  $14
   38    34        ASSIGN                                                   !5, ''
   40    35        ASSIGN                                                   !6, ''
   41    36        INIT_FCALL                                               'array_keys'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                         $27     
         39      > FE_RESET_R                                       $28     $27, ->44
         40    > > FE_FETCH_R                                               $28, !3, ->44
   42    41    >   CONCAT                                           ~29     !3, '%2C'
         42        ASSIGN_OP                                     8          !6, ~29
   41    43      > JMP                                                      ->40
         44    >   FE_FREE                                                  $28
   44    45        ASSIGN                                                   !7, ''
   45    46        COUNT                                            ~32     !2
         47        IS_NOT_IDENTICAL                                         ~32, 0
         48      > JMPZ                                                     ~33, ->71
   46    49    >   INIT_FCALL                                               'parsetrialdata'
         50        INIT_FCALL                                               'array_values'
         51        SEND_VAR                                                 !2
         52        DO_ICALL                                         $34     
         53        FETCH_DIM_R                                      ~35     $34, 0
         54        SEND_VAL                                                 ~35
         55        DO_FCALL                                      0  $36     
         56        ASSIGN                                                   !8, $36
   47    57        INIT_FCALL                                               'array_keys'
         58        SEND_VAR                                                 !8
         59        DO_ICALL                                         $38     
         60      > FE_RESET_R                                       $39     $38, ->70
         61    > > FE_FETCH_R                                               $39, !3, ->70
   48    62    >   INIT_FCALL                                               'substr'
         63        SEND_VAR                                                 !3
         64        SEND_VAL                                                 1
         65        SEND_VAL                                                 -1
         66        DO_ICALL                                         $40     
         67        CONCAT                                           ~41     $40, '%2C'
         68        ASSIGN_OP                                     8          !7, ~41
   47    69      > JMP                                                      ->61
         70    >   FE_FREE                                                  $39
   51    71    >   CONCAT                                           ~43     !6, !7
         72        ASSIGN_OP                                     8          !5, ~43
   52    73        INIT_FCALL                                               'substr'
         74        SEND_VAR                                                 !5
         75        SEND_VAL                                                 0
         76        SEND_VAL                                                 -1
         77        DO_ICALL                                         $45     
         78        CONCAT                                           ~46     $45, '%0A'
         79        ASSIGN                                                   !5, ~46
   54    80        INIT_FCALL                                               'array_values'
         81        SEND_VAR                                                 !2
         82        DO_ICALL                                         $48     
         83      > FE_RESET_R                                       $49     $48, ->88
         84    > > FE_FETCH_R                                               $49, !9, ->88
   55    85    >   CONCAT                                           ~50     !9, '%0A'
         86        ECHO                                                     ~50
   54    87      > JMP                                                      ->84
         88    >   FE_FREE                                                  $49
   59    89      > RETURN                                                   1

Function parsetrialdata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/GVUcU
function name:  parseTrialData
number of ops:  28
compiled vars:  !0 = $trialData, !1 = $parsedTrialData, !2 = $kv, !3 = $exploded
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'substr'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 1
          4        SEND_VAL                                                 -1
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !0, $4
   13     7        INIT_FCALL                                               'explode'
          8        SEND_VAL                                                 '%2C'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $6      
         11        ASSIGN                                                   !0, $6
   16    12        ASSIGN                                                   !1, <array>
   17    13      > FE_RESET_R                                       $9      !0, ->25
         14    > > FE_FETCH_R                                               $9, !2, ->25
   18    15    >   INIT_FCALL                                               'explode'
         16        SEND_VAL                                                 '%3A'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $10     
         19        ASSIGN                                                   !3, $10
   19    20        FETCH_DIM_R                                      ~12     !3, 0
         21        FETCH_DIM_R                                      ~14     !3, 1
         22        ASSIGN_DIM                                               !1, ~12
         23        OP_DATA                                                  ~14
   17    24      > JMP                                                      ->14
         25    >   FE_FREE                                                  $9
   21    26      > RETURN                                                   !1
   22    27*     > RETURN                                                   null

End of function parsetrialdata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.79 ms | 1411 KiB | 24 Q