3v4l.org

run code in 300+ PHP versions simultaneously
<?php $comments='[ { "user": "5", "points": "12" }, { "user": "2", "points": "1" }, { "user": "3", "points": "1" } ]'; $likes='[ { "user": "1", "points": 7 }, { "user": "4", "points": 4 }, { "user": "3", "points": 1 } ]'; $posts='[ { "user": "1", "points": "6" }, { "user": "3", "points": "2" }, { "user": "2", "points": "1" } ]'; $merged = array_merge(json_decode($comments, true), json_decode($likes, true), json_decode($posts, true)); $result = []; foreach ($merged as $entry) { if (!isset($result[$entry['user']])) { $result[$entry['user']] = $entry; } else { $result[$entry['user']]['points'] += $entry['points']; } } array_multisort(array_column($result, 'user'), $result); //usort($result, function($a, $b) { return $a['user']<=>$b['user']; }); // this is the most modern style, change if too advanced for your php version echo json_encode($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 38
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 38
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/nY7ZW
function name:  (null)
number of ops:  52
compiled vars:  !0 = $comments, !1 = $likes, !2 = $posts, !3 = $merged, !4 = $result, !5 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, '%5B%0A++++%7B%0A++++++++%22user%22%3A+%225%22%2C%0A++++++++%22points%22%3A+%2212%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22user%22%3A+%222%22%2C%0A++++++++%22points%22%3A+%221%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22user%22%3A+%223%22%2C%0A++++++++%22points%22%3A+%221%22%0A++++%7D%0A%5D'
   16     1        ASSIGN                                                   !1, '%5B%0A++++%7B%0A++++++++%22user%22%3A+%221%22%2C%0A++++++++%22points%22%3A+7%0A++++%7D%2C%0A++++%7B%0A++++++++%22user%22%3A+%224%22%2C%0A++++++++%22points%22%3A+4%0A++++%7D%2C%0A++++%7B%0A++++++++%22user%22%3A+%223%22%2C%0A++++++++%22points%22%3A+1%0A++++%7D%0A%5D'
   30     2        ASSIGN                                                   !2, '%5B%0A++++%7B%0A++++++++%22user%22%3A+%221%22%2C%0A++++++++%22points%22%3A+%226%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22user%22%3A+%223%22%2C%0A++++++++%22points%22%3A+%222%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22user%22%3A+%222%22%2C%0A++++++++%22points%22%3A+%221%22%0A++++%7D%0A%5D'
   45     3        INIT_FCALL                                               'array_merge'
          4        INIT_FCALL                                               'json_decode'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $9      
          8        SEND_VAR                                                 $9
          9        INIT_FCALL                                               'json_decode'
         10        SEND_VAR                                                 !1
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $10     
         13        SEND_VAR                                                 $10
         14        INIT_FCALL                                               'json_decode'
         15        SEND_VAR                                                 !2
         16        SEND_VAL                                                 <true>
         17        DO_ICALL                                         $11     
         18        SEND_VAR                                                 $11
         19        DO_ICALL                                         $12     
         20        ASSIGN                                                   !3, $12
   46    21        ASSIGN                                                   !4, <array>
   47    22      > FE_RESET_R                                       $15     !3, ->38
         23    > > FE_FETCH_R                                               $15, !5, ->38
   48    24    >   FETCH_DIM_R                                      ~16     !5, 'user'
         25        ISSET_ISEMPTY_DIM_OBJ                         0  ~17     !4, ~16
         26        BOOL_NOT                                         ~18     ~17
         27      > JMPZ                                                     ~18, ->32
   49    28    >   FETCH_DIM_R                                      ~19     !5, 'user'
         29        ASSIGN_DIM                                               !4, ~19
         30        OP_DATA                                                  !5
   48    31      > JMP                                                      ->37
   51    32    >   FETCH_DIM_R                                      ~21     !5, 'user'
         33        FETCH_DIM_R                                      ~24     !5, 'points'
         34        FETCH_DIM_RW                                     $22     !4, ~21
         35        ASSIGN_DIM_OP                +=               1          $22, 'points'
         36        OP_DATA                                                  ~24
   47    37    > > JMP                                                      ->23
         38    >   FE_FREE                                                  $15
   54    39        INIT_FCALL                                               'array_multisort'
         40        INIT_FCALL                                               'array_column'
         41        SEND_VAR                                                 !4
         42        SEND_VAL                                                 'user'
         43        DO_ICALL                                         $25     
         44        SEND_VAL                                                 $25
         45        SEND_REF                                                 !4
         46        DO_ICALL                                                 
   56    47        INIT_FCALL                                               'json_encode'
         48        SEND_VAR                                                 !4
         49        DO_ICALL                                         $27     
         50        ECHO                                                     $27
         51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.59 ms | 1014 KiB | 18 Q