3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'category_id' => 1, 'question_id' => 1, 'option_id' => 2, 'title' => 'Do you wear glasses?', 'answer' => 'no' ], [ 'category_id' => 1, 'question_id' => 2, 'option_id' => 3, 'title' => 'Your hobbies ?', 'answer' => 'movies' ], [ 'category_id' => 1, 'question_id' => 4, 'option_id' => 8, 'title' => 'what is your status?', 'answer' => 'single' ], [ 'category_id' => 1, 'question_id' => 2, 'option_id' => 1, 'title' => 'Your hobbies ?', 'answer' => 'travel' ], ]; $result = []; foreach ($array as $row) { $compositeKey = $row['category_id'] . '_' . $row['question_id']; if (!isset($result[$compositeKey])) { $result[$compositeKey] = $row; } else { $result[$compositeKey]['answer'] .= ",{$row['answer']}"; } } var_export( array_values( $result ) );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 22
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/9NEHS
function name:  (null)
number of ops:  30
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $compositeKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   34     1        ASSIGN                                                   !1, <array>
   35     2      > FE_RESET_R                                       $6      !0, ->22
          3    > > FE_FETCH_R                                               $6, !2, ->22
   36     4    >   FETCH_DIM_R                                      ~7      !2, 'category_id'
          5        CONCAT                                           ~8      ~7, '_'
          6        FETCH_DIM_R                                      ~9      !2, 'question_id'
          7        CONCAT                                           ~10     ~8, ~9
          8        ASSIGN                                                   !3, ~10
   37     9        ISSET_ISEMPTY_DIM_OBJ                         0  ~12     !1, !3
         10        BOOL_NOT                                         ~13     ~12
         11      > JMPZ                                                     ~13, ->15
   38    12    >   ASSIGN_DIM                                               !1, !3
         13        OP_DATA                                                  !2
   37    14      > JMP                                                      ->21
   40    15    >   NOP                                                      
         16        FETCH_DIM_R                                      ~17     !2, 'answer'
         17        FAST_CONCAT                                      ~18     '%2C', ~17
         18        FETCH_DIM_RW                                     $15     !1, !3
         19        ASSIGN_DIM_OP                .=               8          $15, 'answer'
         20        OP_DATA                                                  ~18
   35    21    > > JMP                                                      ->3
         22    >   FE_FREE                                                  $6
   43    23        INIT_FCALL                                               'var_export'
   44    24        INIT_FCALL                                               'array_values'
   45    25        SEND_VAR                                                 !1
   44    26        DO_ICALL                                         $19     
   45    27        SEND_VAR                                                 $19
   43    28        DO_ICALL                                                 
   47    29      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.51 ms | 1004 KiB | 15 Q