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]; $pair = array($key, $value); if (substr($value[1], 0, 1) == '{' and substr($value, -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(localHeader) !== 0) { $parsedSampleTrialData = parseTrialData(array_values($trialData)[0]); foreach (array_keys($parsedSampleTrialData) as $key) { $localHeader .= $key . ","; } } $header .= $globalHeader . $localHeader; $header = substr($header, 0, -1) . "\n"; echo $header; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 34
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 21, Position 2 = 27
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 31
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 27
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 45
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 68
Branch analysis from position: 51
2 jumps found. (Code = 77) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
2 jumps found. (Code = 78) Position 1 = 64, Position 2 = 67
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 67
Branch analysis from position: 68
Branch analysis from position: 45
Branch analysis from position: 34
filename:       /in/EtWNH
function name:  (null)
number of ops:  79
compiled vars:  !0 = $arr, !1 = $headerItems, !2 = $trialData, !3 = $key, !4 = $value, !5 = $pair, !6 = $header, !7 = $globalHeader, !8 = $localHeader, !9 = $parsedSampleTrialData
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, ->34
          7    > > FE_FETCH_R                                               $14, !3, ->34
   27     8    >   FETCH_DIM_R                                      ~15     !0, !3
          9        ASSIGN                                                   !4, ~15
   28    10        INIT_ARRAY                                       ~17     !3
         11        ADD_ARRAY_ELEMENT                                ~17     !4
         12        ASSIGN                                                   !5, ~17
   29    13        INIT_FCALL                                               'substr'
         14        FETCH_DIM_R                                      ~19     !4, 1
         15        SEND_VAL                                                 ~19
         16        SEND_VAL                                                 0
         17        SEND_VAL                                                 1
         18        DO_ICALL                                         $20     
         19        IS_EQUAL                                         ~21     $20, '%7B'
         20      > JMPZ_EX                                          ~21     ~21, ->27
         21    >   INIT_FCALL                                               'substr'
         22        SEND_VAR                                                 !4
         23        SEND_VAL                                                 -1
         24        DO_ICALL                                         $22     
         25        IS_EQUAL                                         ~23     $22, '%7B'
         26        BOOL                                             ~21     ~23
         27    > > JMPZ                                                     ~21, ->31
   32    28    >   ASSIGN_DIM                                               !2, !3
         29        OP_DATA                                                  !4
         30      > JMP                                                      ->33
   35    31    >   ASSIGN_DIM                                               !1, !3
         32        OP_DATA                                                  !4
   26    33    > > JMP                                                      ->7
         34    >   FE_FREE                                                  $14
   39    35        ASSIGN                                                   !6, ''
   41    36        ASSIGN                                                   !7, ''
   42    37        INIT_FCALL                                               'array_keys'
         38        SEND_VAR                                                 !1
         39        DO_ICALL                                         $28     
         40      > FE_RESET_R                                       $29     $28, ->45
         41    > > FE_FETCH_R                                               $29, !3, ->45
   43    42    >   CONCAT                                           ~30     !3, '%2C'
         43        ASSIGN_OP                                     8          !7, ~30
   42    44      > JMP                                                      ->41
         45    >   FE_FREE                                                  $29
   45    46        ASSIGN                                                   !8, ''
   46    47        FETCH_CONSTANT                                   ~33     'localHeader'
         48        COUNT                                            ~34     ~33
         49        IS_NOT_IDENTICAL                                         ~34, 0
         50      > JMPZ                                                     ~35, ->68
   47    51    >   INIT_FCALL                                               'parsetrialdata'
         52        INIT_FCALL                                               'array_values'
         53        SEND_VAR                                                 !2
         54        DO_ICALL                                         $36     
         55        FETCH_DIM_R                                      ~37     $36, 0
         56        SEND_VAL                                                 ~37
         57        DO_FCALL                                      0  $38     
         58        ASSIGN                                                   !9, $38
   48    59        INIT_FCALL                                               'array_keys'
         60        SEND_VAR                                                 !9
         61        DO_ICALL                                         $40     
         62      > FE_RESET_R                                       $41     $40, ->67
         63    > > FE_FETCH_R                                               $41, !3, ->67
   49    64    >   CONCAT                                           ~42     !3, '%2C'
         65        ASSIGN_OP                                     8          !8, ~42
   48    66      > JMP                                                      ->63
         67    >   FE_FREE                                                  $41
   52    68    >   CONCAT                                           ~44     !7, !8
         69        ASSIGN_OP                                     8          !6, ~44
   53    70        INIT_FCALL                                               'substr'
         71        SEND_VAR                                                 !6
         72        SEND_VAL                                                 0
         73        SEND_VAL                                                 -1
         74        DO_ICALL                                         $46     
         75        CONCAT                                           ~47     $46, '%0A'
         76        ASSIGN                                                   !6, ~47
   56    77        ECHO                                                     !6
   58    78      > 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/EtWNH
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:
174.13 ms | 1407 KiB | 22 Q