3v4l.org

run code in 300+ PHP versions simultaneously
<?php function transformQuestionnaire($arr) { $new_arr = array(); foreach ($arr as $array){ $key = reset($array); $val = end($array); if (!in_array($key, array_keys($new_arr))){ //not a double $new_arr[$key] = $val; } else { //Append it to the existing value $new_arr[$key] = $new_arr[$key] . '|' . $val; } } return $new_arr; } $input = array( 1 => array("one", "potato"), 2 => array("two", "fries"), 3 => array("one", "ketchup"), ); print(var_dump(transformQuestionnaire($input))); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/LINqS
function name:  (null)
number of ops:  9
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'transformquestionnaire'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                         $3      
          7        ECHO                                                     $3
   24     8      > RETURN                                                   1

Function transformquestionnaire:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 30
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 30
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/LINqS
function name:  transformQuestionnaire
number of ops:  33
compiled vars:  !0 = $arr, !1 = $new_arr, !2 = $array, !3 = $key, !4 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    4     2      > FE_RESET_R                                       $6      !0, ->30
          3    > > FE_FETCH_R                                               $6, !2, ->30
    5     4    >   INIT_FCALL                                               'reset'
          5        SEND_REF                                                 !2
          6        DO_ICALL                                         $7      
          7        ASSIGN                                                   !3, $7
    6     8        INIT_FCALL                                               'end'
          9        SEND_REF                                                 !2
         10        DO_ICALL                                         $9      
         11        ASSIGN                                                   !4, $9
    7    12        INIT_FCALL                                               'in_array'
         13        SEND_VAR                                                 !3
         14        INIT_FCALL                                               'array_keys'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $11     
         17        SEND_VAR                                                 $11
         18        DO_ICALL                                         $12     
         19        BOOL_NOT                                         ~13     $12
         20      > JMPZ                                                     ~13, ->24
    8    21    >   ASSIGN_DIM                                               !1, !3
         22        OP_DATA                                                  !4
         23      > JMP                                                      ->29
   10    24    >   FETCH_DIM_R                                      ~16     !1, !3
         25        CONCAT                                           ~17     ~16, '%7C'
         26        CONCAT                                           ~18     ~17, !4
         27        ASSIGN_DIM                                               !1, !3
         28        OP_DATA                                                  ~18
    4    29    > > JMP                                                      ->3
         30    >   FE_FREE                                                  $6
   13    31      > RETURN                                                   !1
   14    32*     > RETURN                                                   null

End of function transformquestionnaire

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.08 ms | 1402 KiB | 24 Q