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"; $data = ""; // one line for each trial data point, starting with header items, then trial data foreach (array_values($trialData) as $trialStr) { $trialParsed = parseTrialData($trialStr); foreach (array_values($trialParsed) as $trialDataPoint) { $data .= $trialDataPoint . ","; } $data = mb_substr(data, 0, -1) . "\n"; } echo $data; ?>
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 = 85, Position 2 = 108
Branch analysis from position: 85
2 jumps found. (Code = 78) Position 1 = 86, Position 2 = 108
Branch analysis from position: 86
2 jumps found. (Code = 77) Position 1 = 94, Position 2 = 98
Branch analysis from position: 94
2 jumps found. (Code = 78) Position 1 = 95, Position 2 = 98
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 85
Branch analysis from position: 85
Branch analysis from position: 98
Branch analysis from position: 108
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 108
Branch analysis from position: 70
Branch analysis from position: 71
Branch analysis from position: 44
Branch analysis from position: 33
filename:       /in/oivqg
function name:  (null)
number of ops:  111
compiled vars:  !0 = $arr, !1 = $headerItems, !2 = $trialData, !3 = $key, !4 = $value, !5 = $header, !6 = $globalHeader, !7 = $localHeader, !8 = $parsedSampleTrialData, !9 = $data, !10 = $trialStr, !11 = $trialParsed, !12 = $trialDataPoint
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                                         $16     
          6      > FE_RESET_R                                       $17     $16, ->33
          7    > > FE_FETCH_R                                               $17, !3, ->33
   27     8    >   FETCH_DIM_R                                      ~18     !0, !3
          9        ASSIGN                                                   !4, ~18
   28    10        INIT_FCALL                                               'mb_substr'
         11        SEND_VAR                                                 !4
         12        SEND_VAL                                                 0
         13        SEND_VAL                                                 1
         14        DO_ICALL                                         $20     
         15        IS_EQUAL                                         ~21     $20, '%7B'
         16      > JMPZ_EX                                          ~21     ~21, ->26
         17    >   INIT_FCALL                                               'mb_substr'
         18        SEND_VAR                                                 !4
         19        STRLEN                                           ~22     !4
         20        SUB                                              ~23     ~22, 1
         21        SEND_VAL                                                 ~23
         22        SEND_VAL                                                 1
         23        DO_ICALL                                         $24     
         24        IS_EQUAL                                         ~25     $24, '%7D'
         25        BOOL                                             ~21     ~25
         26    > > JMPZ                                                     ~21, ->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                                                  $17
   38    34        ASSIGN                                                   !5, ''
   40    35        ASSIGN                                                   !6, ''
   41    36        INIT_FCALL                                               'array_keys'
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                         $30     
         39      > FE_RESET_R                                       $31     $30, ->44
         40    > > FE_FETCH_R                                               $31, !3, ->44
   42    41    >   CONCAT                                           ~32     !3, '%2C'
         42        ASSIGN_OP                                     8          !6, ~32
   41    43      > JMP                                                      ->40
         44    >   FE_FREE                                                  $31
   44    45        ASSIGN                                                   !7, ''
   45    46        COUNT                                            ~35     !2
         47        IS_NOT_IDENTICAL                                         ~35, 0
         48      > JMPZ                                                     ~36, ->71
   46    49    >   INIT_FCALL                                               'parsetrialdata'
         50        INIT_FCALL                                               'array_values'
         51        SEND_VAR                                                 !2
         52        DO_ICALL                                         $37     
         53        FETCH_DIM_R                                      ~38     $37, 0
         54        SEND_VAL                                                 ~38
         55        DO_FCALL                                      0  $39     
         56        ASSIGN                                                   !8, $39
   47    57        INIT_FCALL                                               'array_keys'
         58        SEND_VAR                                                 !8
         59        DO_ICALL                                         $41     
         60      > FE_RESET_R                                       $42     $41, ->70
         61    > > FE_FETCH_R                                               $42, !3, ->70
   48    62    >   INIT_FCALL                                               'substr'
         63        SEND_VAR                                                 !3
         64        SEND_VAL                                                 1
         65        SEND_VAL                                                 -1
         66        DO_ICALL                                         $43     
         67        CONCAT                                           ~44     $43, '%2C'
         68        ASSIGN_OP                                     8          !7, ~44
   47    69      > JMP                                                      ->61
         70    >   FE_FREE                                                  $42
   51    71    >   CONCAT                                           ~46     !6, !7
         72        ASSIGN_OP                                     8          !5, ~46
   52    73        INIT_FCALL                                               'substr'
         74        SEND_VAR                                                 !5
         75        SEND_VAL                                                 0
         76        SEND_VAL                                                 -1
         77        DO_ICALL                                         $48     
         78        CONCAT                                           ~49     $48, '%0A'
         79        ASSIGN                                                   !5, ~49
   54    80        ASSIGN                                                   !9, ''
   56    81        INIT_FCALL                                               'array_values'
         82        SEND_VAR                                                 !2
         83        DO_ICALL                                         $52     
         84      > FE_RESET_R                                       $53     $52, ->108
         85    > > FE_FETCH_R                                               $53, !10, ->108
   57    86    >   INIT_FCALL                                               'parsetrialdata'
         87        SEND_VAR                                                 !10
         88        DO_FCALL                                      0  $54     
         89        ASSIGN                                                   !11, $54
   58    90        INIT_FCALL                                               'array_values'
         91        SEND_VAR                                                 !11
         92        DO_ICALL                                         $56     
         93      > FE_RESET_R                                       $57     $56, ->98
         94    > > FE_FETCH_R                                               $57, !12, ->98
   59    95    >   CONCAT                                           ~58     !12, '%2C'
         96        ASSIGN_OP                                     8          !9, ~58
   58    97      > JMP                                                      ->94
         98    >   FE_FREE                                                  $57
   61    99        INIT_FCALL                                               'mb_substr'
        100        FETCH_CONSTANT                                   ~60     'data'
        101        SEND_VAL                                                 ~60
        102        SEND_VAL                                                 0
        103        SEND_VAL                                                 -1
        104        DO_ICALL                                         $61     
        105        CONCAT                                           ~62     $61, '%0A'
        106        ASSIGN                                                   !9, ~62
   56   107      > JMP                                                      ->85
        108    >   FE_FREE                                                  $53
   64   109        ECHO                                                     !9
   67   110      > 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/oivqg
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:
188.63 ms | 1411 KiB | 25 Q