3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '[ { "date": "2022-02-15", "websites": [ { "website_name": "instagram", "num_followers": "123146780" }, { "website_name": "instagram", "num_followers": "123134954" }, { "website_name": "tiktok", "num_followers": "123184229" } ] }, { "date": "2022-02-14", "websites": [ { "website_name": "instagram", "num_followers": "123057832" }, { "website_name": "tiktok", "num_followers": "123058141" }, { "website_name": "tiktok", "num_followers": "123058219" }, { "website_name": "instagram", "num_followers": "123059280" } ] } ]'; $data = []; foreach (json_decode($input, true) as $day) { $items['date'] = $day['date']; $sites = []; foreach ($day['websites'] as $site) { $name = $site['website_name']; if (key_exists($name, $sites) === false) { $sites[$name] = $site; continue; } if ($sites[$name]['num_followers'] < $site['num_followers']) { $sites[$name] = $site; } } $items['websites'] = array_values($sites); $data[] = $items; } var_dump(json_encode($data, JSON_PRETTY_PRINT));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 43
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 43
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 34
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 34
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 33
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 34
Branch analysis from position: 43
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
filename:       /in/RZU5s
function name:  (null)
number of ops:  52
compiled vars:  !0 = $input, !1 = $data, !2 = $day, !3 = $items, !4 = $sites, !5 = $site, !6 = $name
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A++++%7B%0A++++++++%22date%22%3A+%222022-02-15%22%2C%0A++++++++%22websites%22%3A+%5B%0A++++++++++++%7B%0A++++++++++++++++%22website_name%22%3A+%22instagram%22%2C%0A++++++++++++++++%22num_followers%22%3A+%22123146780%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22website_name%22%3A+%22instagram%22%2C%0A++++++++++++++++%22num_followers%22%3A+%22123134954%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22website_name%22%3A+%22tiktok%22%2C%0A++++++++++++++++%22num_followers%22%3A+%22123184229%22%0A++++++++++++%7D%0A++++++++%5D%0A++++%7D%2C%0A++++%7B%0A++++++++%22date%22%3A+%222022-02-14%22%2C%0A++++++++%22websites%22%3A+%5B%0A++++++++++++%7B%0A++++++++++++++++%22website_name%22%3A+%22instagram%22%2C%0A++++++++++++++++%22num_followers%22%3A+%22123057832%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22website_name%22%3A+%22tiktok%22%2C%0A++++++++++++++++%22num_followers%22%3A+%22123058141%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22website_name%22%3A+%22tiktok%22%2C%0A++++++++++++++++%22num_followers%22%3A+%22123058219%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22website_name%22%3A+%22instagram%22%2C%0A++++++++++++++++%22num_followers%22%3A+%22123059280%22%0A++++++++++++%7D%0A++++++++%5D%0A++++%7D%0A%5D'
   45     1        ASSIGN                                                   !1, <array>
   46     2        INIT_FCALL                                               'json_decode'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $9      
          6      > FE_RESET_R                                       $10     $9, ->43
          7    > > FE_FETCH_R                                               $10, !2, ->43
   47     8    >   FETCH_DIM_R                                      ~12     !2, 'date'
          9        ASSIGN_DIM                                               !3, 'date'
         10        OP_DATA                                                  ~12
   48    11        ASSIGN                                                   !4, <array>
   50    12        FETCH_DIM_R                                      ~14     !2, 'websites'
         13      > FE_RESET_R                                       $15     ~14, ->34
         14    > > FE_FETCH_R                                               $15, !5, ->34
   51    15    >   FETCH_DIM_R                                      ~16     !5, 'website_name'
         16        ASSIGN                                                   !6, ~16
   52    17        INIT_FCALL                                               'key_exists'
         18        SEND_VAR                                                 !6
         19        SEND_VAR                                                 !4
         20        DO_ICALL                                         $18     
         21        TYPE_CHECK                                    4          $18
         22      > JMPZ                                                     ~19, ->26
   53    23    >   ASSIGN_DIM                                               !4, !6
         24        OP_DATA                                                  !5
   54    25      > JMP                                                      ->14
   57    26    >   FETCH_DIM_R                                      ~21     !4, !6
         27        FETCH_DIM_R                                      ~22     ~21, 'num_followers'
         28        FETCH_DIM_R                                      ~23     !5, 'num_followers'
         29        IS_SMALLER                                               ~22, ~23
         30      > JMPZ                                                     ~24, ->33
   58    31    >   ASSIGN_DIM                                               !4, !6
         32        OP_DATA                                                  !5
   50    33    > > JMP                                                      ->14
         34    >   FE_FREE                                                  $15
   62    35        INIT_FCALL                                               'array_values'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                         $27     
         38        ASSIGN_DIM                                               !3, 'websites'
         39        OP_DATA                                                  $27
   64    40        ASSIGN_DIM                                               !1
         41        OP_DATA                                                  !3
   46    42      > JMP                                                      ->7
         43    >   FE_FREE                                                  $10
   68    44        INIT_FCALL                                               'var_dump'
         45        INIT_FCALL                                               'json_encode'
         46        SEND_VAR                                                 !1
         47        SEND_VAL                                                 128
         48        DO_ICALL                                         $29     
         49        SEND_VAR                                                 $29
         50        DO_ICALL                                                 
         51      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.65 ms | 1009 KiB | 18 Q