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