3v4l.org

run code in 500+ PHP versions simultaneously
<?php $weights = ['1 Kg','300 g','1.5 Kg','20.5 g','5 Kg']; $r = []; foreach ($weights as $v) { if (strpos($v, 'g') !== false) {$k = 1;} // 1 g if (strpos($v, 'Kg') !== false) {$k = 1000;} // 1 kilogram = 1000 g $r[floatval($v)*$k] = $v; } ksort($r);//ksort used to sort array by key print_r($r);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 8
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 12
Branch analysis from position: 8
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/1btER
function name:  (null)
number of ops:  25
compiled vars:  !0 = $weights, !1 = $r, !2 = $v, !3 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    5     1        ASSIGN                                                       !1, <array>
    7     2      > FE_RESET_R                                           $6      !0, ->17
          3    > > FE_FETCH_R                                                   $6, !2, ->17
    9     4    >   FRAMELESS_ICALL_2                strpos              ~7      !2, 'g'
          5        TYPE_CHECK                                      1018          ~7
          6      > JMPZ                                                         ~8, ->8
          7    >   ASSIGN                                                       !3, 1
   10     8    >   FRAMELESS_ICALL_2                strpos              ~10     !2, 'Kg'
          9        TYPE_CHECK                                      1018          ~10
         10      > JMPZ                                                         ~11, ->12
         11    >   ASSIGN                                                       !3, 1000
   12    12    >   CAST                                              5  ~13     !2
         13        MUL                                                  ~14     !3, ~13
         14        ASSIGN_DIM                                                   !1, ~14
         15        OP_DATA                                                      !2
    7    16      > JMP                                                          ->3
         17    >   FE_FREE                                                      $6
   14    18        INIT_FCALL                                                   'ksort'
         19        SEND_REF                                                     !1
         20        DO_ICALL                                                     
   15    21        INIT_FCALL                                                   'print_r'
         22        SEND_VAR                                                     !1
         23        DO_ICALL                                                     
         24      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
157.55 ms | 1911 KiB | 15 Q