3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = [ [ '0-300' => 2.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.4, '>5000' => 2.4 ], [ '0-300' => 1.2, '300-500' => 1.2, '500-1000' => 1.2, '1000-5000' => 1.3, '>5000' => 1.4 ], [ '0-300' => 2.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.5, '>5000' => 2.5 ], [ '0-300' => 4.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.5, '>5000' => 3.5 ], [ '0-300' => 4.5, '300-500' => 3.5, '500-1000' => 3.5, '1000-5000' => 3.5, '>5000' => 3.5 ], [ '0-300' => 1.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.5, '>5000' => 1.5 ], [ '0-300' => 1.5, '300-500' => 2.5, '500-1000' => 3.5, '1000-5000' => 2.5, '>5000' => 3.5 ], [ '0-300' => 1.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 1.5, '>5000' => 1.5 ] ]; $result = []; foreach ($array as $row) { $merged = []; $entry = ['lb' => null, 'ub' => null, 'value' => null]; foreach ($row as $range => $value) { sscanf(ltrim("$range-INF", '>'), '%[^-]-%[^-]', $lowerBound, $upperBound); if ($value !== $entry['value']) { $entry['ub'] = $lowerBound; if ($entry['lb'] !== null) { $merged[] = $entry; } $entry['lb'] = $lowerBound; $entry['value'] = $value; } } $entry['ub'] = $upperBound; $merged[] = $entry; echo json_encode($merged) . "\n\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 47
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 47
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 36
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 36
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 31
Branch analysis from position: 35
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 36
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/PF1RC
function name:  (null)
number of ops:  49
compiled vars:  !0 = $array, !1 = $result, !2 = $row, !3 = $merged, !4 = $entry, !5 = $value, !6 = $range, !7 = $lowerBound, !8 = $upperBound
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   14     1        ASSIGN                                                       !1, <array>
   15     2      > FE_RESET_R                                           $11     !0, ->47
          3    > > FE_FETCH_R                                                   $11, !2, ->47
   16     4    >   ASSIGN                                                       !3, <array>
   17     5        ASSIGN                                                       !4, <array>
   18     6      > FE_RESET_R                                           $14     !2, ->36
          7    > > FE_FETCH_R                                           ~15     $14, !5, ->36
          8    >   ASSIGN                                                       !6, ~15
   19     9        INIT_FCALL                                                   'sscanf'
         10        INIT_FCALL                                                   'ltrim'
         11        NOP                                                          
         12        FAST_CONCAT                                          ~17     !6, '-INF'
         13        SEND_VAL                                                     ~17
         14        SEND_VAL                                                     '%3E'
         15        DO_ICALL                                             $18     
         16        SEND_VAR                                                     $18
         17        SEND_VAL                                                     '%25%5B%5E-%5D-%25%5B%5E-%5D'
         18        SEND_REF                                                     !7
         19        SEND_REF                                                     !8
         20        DO_ICALL                                                     
   20    21        FETCH_DIM_R                                          ~20     !4, 'value'
         22        IS_NOT_IDENTICAL                                             !5, ~20
         23      > JMPZ                                                         ~21, ->35
   21    24    >   ASSIGN_DIM                                                   !4, 'ub'
         25        OP_DATA                                                      !7
   22    26        FETCH_DIM_R                                          ~23     !4, 'lb'
         27        TYPE_CHECK                                      1020          ~23
         28      > JMPZ                                                         ~24, ->31
   23    29    >   ASSIGN_DIM                                                   !3
         30        OP_DATA                                                      !4
   25    31    >   ASSIGN_DIM                                                   !4, 'lb'
         32        OP_DATA                                                      !7
   26    33        ASSIGN_DIM                                                   !4, 'value'
         34        OP_DATA                                                      !5
   18    35    > > JMP                                                          ->7
         36    >   FE_FREE                                                      $14
   29    37        ASSIGN_DIM                                                   !4, 'ub'
         38        OP_DATA                                                      !8
   30    39        ASSIGN_DIM                                                   !3
         40        OP_DATA                                                      !4
   31    41        INIT_FCALL                                                   'json_encode'
         42        SEND_VAR                                                     !3
         43        DO_ICALL                                             $30     
         44        CONCAT                                               ~31     $30, '%0A%0A'
         45        ECHO                                                         ~31
   15    46      > JMP                                                          ->3
         47    >   FE_FREE                                                      $11
   32    48      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.08 ms | 2043 KiB | 16 Q