3v4l.org

run code in 300+ PHP versions simultaneously
<?php function transformQuestionnaire($arr) { $new_arr = array(); foreach ($arr as $nr => $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/gefJ5
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 = 26
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/gefJ5
function name:  transformQuestionnaire
number of ops:  29
compiled vars:  !0 = $arr, !1 = $new_arr, !2 = $array, !3 = $nr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        ASSIGN                                                   !1, <array>
    4     2      > FE_RESET_R                                       $5      !0, ->26
          3    > > FE_FETCH_R                                       ~6      $5, !2, ->26
          4    >   ASSIGN                                                   !3, ~6
    5     5        INIT_FCALL                                               'in_array'
          6        FETCH_DIM_R                                      ~8      !2, 0
          7        SEND_VAL                                                 ~8
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $9      
         10        BOOL_NOT                                         ~10     $9
         11      > JMPZ                                                     ~10, ->17
    6    12    >   FETCH_DIM_R                                      ~11     !2, 0
         13        FETCH_DIM_R                                      ~13     !2, 1
         14        ASSIGN_DIM                                               !1, ~11
         15        OP_DATA                                                  ~13
         16      > JMP                                                      ->25
    8    17    >   FETCH_DIM_R                                      ~14     !2, 0
         18        FETCH_DIM_R                                      ~16     !2, 0
         19        FETCH_DIM_R                                      ~17     !1, ~16
         20        CONCAT                                           ~18     ~17, '%7C'
         21        FETCH_DIM_R                                      ~19     !2, 1
         22        CONCAT                                           ~20     ~18, ~19
         23        ASSIGN_DIM                                               !1, ~14
         24        OP_DATA                                                  ~20
    4    25    > > JMP                                                      ->3
         26    >   FE_FREE                                                  $5
   11    27      > RETURN                                                   !1
   12    28*     > RETURN                                                   null

End of function transformquestionnaire

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.67 ms | 1394 KiB | 18 Q