3v4l.org

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.83 ms | 1004 KiB | 16 Q