3v4l.org

run code in 300+ PHP versions simultaneously
<?php function transformQuestionnaire($arr) { $new_arr = array(); foreach ($arr as $array){ if (!in_array($array[0], $new_arr)){ //not a double $new_arr[$array[0]] = $array[1]; } else { //Append it to the existing value $new_arr[$array[0]] = $new_arr[$array[0]] . '|' . $array[1]; } } 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/ce36p
function name:  (null)
number of ops:  9
compiled vars:  !0 = $input
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, <array>
   20     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
   22     8      > RETURN                                                   1

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

End of function transformquestionnaire

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.43 ms | 1407 KiB | 18 Q