3v4l.org

run code in 500+ PHP versions simultaneously
<?php $json = <<<JSON [ { "fight_declaration": "1" }, { "fight_declaration": "2" }, { "fight_declaration": "2" }, { "fight_declaration": "1" }, { "fight_declaration": "3" } ] JSON; $data = json_decode($json, false, 512, JSON_THROW_ON_ERROR); $counts = []; foreach ($data as $entry) { if (!isset($previous)) { $currentCount = ['count' => 1]; } elseif ($entry->fight_declaration === $previous->fight_declaration) { $currentCount['count']++; } else { $counts[] = $currentCount; $currentCount = ['count' => 1]; } $previous = $entry; } if (isset($currentCount)) { $counts[] = $currentCount; } print_r($counts);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 28
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 28
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 33
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 28
filename:       /in/eAjf0
function name:  (null)
number of ops:  37
compiled vars:  !0 = $json, !1 = $data, !2 = $counts, !3 = $entry, !4 = $previous, !5 = $currentCount
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, '%5B%0A++++%7B%0A++++++++%22fight_declaration%22%3A+%221%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22fight_declaration%22%3A+%222%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22fight_declaration%22%3A+%222%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22fight_declaration%22%3A+%221%22%0A++++%7D%2C%0A++++%7B%0A++++++++%22fight_declaration%22%3A+%223%22%0A++++%7D%0A%5D'
   23     1        INIT_FCALL                                                   'json_decode'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     <false>
          4        SEND_VAL                                                     512
          5        SEND_VAL                                                     4194304
          6        DO_ICALL                                             $7      
          7        ASSIGN                                                       !1, $7
   25     8        ASSIGN                                                       !2, <array>
   26     9      > FE_RESET_R                                           $10     !1, ->28
         10    > > FE_FETCH_R                                                   $10, !3, ->28
   27    11    >   ISSET_ISEMPTY_CV                                     ~11     !4
         12        BOOL_NOT                                             ~12     ~11
         13      > JMPZ                                                         ~12, ->16
   28    14    >   ASSIGN                                                       !5, <array>
   27    15      > JMP                                                          ->26
   29    16    >   FETCH_OBJ_R                                          ~14     !3, 'fight_declaration'
         17        FETCH_OBJ_R                                          ~15     !4, 'fight_declaration'
         18        IS_IDENTICAL                                                 ~14, ~15
         19      > JMPZ                                                         ~16, ->23
   30    20    >   FETCH_DIM_RW                                         $17     !5, 'count'
         21        PRE_INC                                                      $17
   29    22      > JMP                                                          ->26
   32    23    >   ASSIGN_DIM                                                   !2
         24        OP_DATA                                                      !5
   33    25        ASSIGN                                                       !5, <array>
   35    26    >   ASSIGN                                                       !4, !3
   26    27      > JMP                                                          ->10
         28    >   FE_FREE                                                      $10
   37    29        ISSET_ISEMPTY_CV                                             !5
         30      > JMPZ                                                         ~22, ->33
   38    31    >   ASSIGN_DIM                                                   !2
         32        OP_DATA                                                      !5
   41    33    >   INIT_FCALL                                                   'print_r'
         34        SEND_VAR                                                     !2
         35        DO_ICALL                                                     
         36      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.43 ms | 2171 KiB | 15 Q