3v4l.org

run code in 300+ PHP versions simultaneously
<?php $source=json_decode('[{"title":"games","transaction_id":102,"order_id":"a"},{"title":"media","transaction_id":95,"order_id":"b"},{"title":"tv","transaction_id":102,"order_id":"a"},{"title":"jane","transaction_id":42,"order_id":"a"},{"title":"ads","transaction_id":95,"order_id":"b"},{"title":"movie","transaction_id":95,"order_id":"c"}]',true); function merge(array $source) { $result=array(); foreach($source as $node) { $key=$node["transaction_id"]."_".$node["order_id"]; if(!empty($result[$key])) $result[$key][]=$node["title"]; else $result[$key]=array($node["title"]); } return array_values($result); } print_r($source);//Just for debug print_r(merge($source));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/e3ERO
function name:  (null)
number of ops:  15
compiled vars:  !0 = $source
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%5B%7B%22title%22%3A%22games%22%2C%22transaction_id%22%3A102%2C%22order_id%22%3A%22a%22%7D%2C%7B%22title%22%3A%22media%22%2C%22transaction_id%22%3A95%2C%22order_id%22%3A%22b%22%7D%2C%7B%22title%22%3A%22tv%22%2C%22transaction_id%22%3A102%2C%22order_id%22%3A%22a%22%7D%2C%7B%22title%22%3A%22jane%22%2C%22transaction_id%22%3A42%2C%22order_id%22%3A%22a%22%7D%2C%7B%22title%22%3A%22ads%22%2C%22transaction_id%22%3A95%2C%22order_id%22%3A%22b%22%7D%2C%7B%22title%22%3A%22movie%22%2C%22transaction_id%22%3A95%2C%22order_id%22%3A%22c%22%7D%5D'
          2        SEND_VAL                                                 <true>
          3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   14     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                                 
   15     8        INIT_FCALL                                               'print_r'
          9        INIT_FCALL                                               'merge'
         10        SEND_VAR                                                 !0
         11        DO_FCALL                                      0  $4      
         12        SEND_VAR                                                 $4
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function merge:
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 = 17
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: 17
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/e3ERO
function name:  merge
number of ops:  28
compiled vars:  !0 = $source, !1 = $result, !2 = $node, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2      > FE_RESET_R                                       $5      !0, ->22
          3    > > FE_FETCH_R                                               $5, !2, ->22
    8     4    >   FETCH_DIM_R                                      ~6      !2, 'transaction_id'
          5        CONCAT                                           ~7      ~6, '_'
          6        FETCH_DIM_R                                      ~8      !2, 'order_id'
          7        CONCAT                                           ~9      ~7, ~8
          8        ASSIGN                                                   !3, ~9
    9     9        ISSET_ISEMPTY_DIM_OBJ                         1  ~11     !1, !3
         10        BOOL_NOT                                         ~12     ~11
         11      > JMPZ                                                     ~12, ->17
         12    >   FETCH_DIM_R                                      ~15     !2, 'title'
         13        FETCH_DIM_W                                      $13     !1, !3
         14        ASSIGN_DIM                                               $13
         15        OP_DATA                                                  ~15
         16      > JMP                                                      ->21
   10    17    >   FETCH_DIM_R                                      ~17     !2, 'title'
         18        INIT_ARRAY                                       ~18     ~17
         19        ASSIGN_DIM                                               !1, !3
         20        OP_DATA                                                  ~18
    6    21    > > JMP                                                      ->3
         22    >   FE_FREE                                                  $5
   12    23        INIT_FCALL                                               'array_values'
         24        SEND_VAR                                                 !1
         25        DO_ICALL                                         $19     
         26      > RETURN                                                   $19
   13    27*     > RETURN                                                   null

End of function merge

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.66 ms | 1403 KiB | 20 Q