3v4l.org

run code in 500+ PHP versions simultaneously
<?php const UNIT_FACTOR = [ 'g' => 1, 'Kg' => 1000, ]; $weights = ['1 Kg','300 g','1.5 Kg','20 g','5 Kg']; foreach ($weights as $weight) { sscanf($weight, '%f %s', $amount, $unit); $grams[] = $amount * UNIT_FACTOR[$unit]; } array_multisort($grams, $weights); var_export($weights);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/oQP3G
function name:  (null)
number of ops:  25
compiled vars:  !0 = $weights, !1 = $weight, !2 = $amount, !3 = $unit, !4 = $grams
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   DECLARE_CONST                                                'UNIT_FACTOR', <array>
    8     1        ASSIGN                                                       !0, <array>
   10     2      > FE_RESET_R                                           $6      !0, ->16
          3    > > FE_FETCH_R                                                   $6, !1, ->16
   11     4    >   INIT_FCALL                                                   'sscanf'
          5        SEND_VAR                                                     !1
          6        SEND_VAL                                                     '%25f+%25s'
          7        SEND_REF                                                     !2
          8        SEND_REF                                                     !3
          9        DO_ICALL                                                     
   12    10        FETCH_CONSTANT                                       ~9      'UNIT_FACTOR'
         11        FETCH_DIM_R                                          ~10     ~9, !3
         12        MUL                                                  ~11     !2, ~10
         13        ASSIGN_DIM                                                   !4
         14        OP_DATA                                                      ~11
   10    15      > JMP                                                          ->3
         16    >   FE_FREE                                                      $6
   15    17        INIT_FCALL                                                   'array_multisort'
         18        SEND_REF                                                     !4
         19        SEND_REF                                                     !0
         20        DO_ICALL                                                     
   16    21        INIT_FCALL                                                   'var_export'
         22        SEND_VAR                                                     !0
         23        DO_ICALL                                                     
         24      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.51 ms | 1895 KiB | 16 Q