3v4l.org

run code in 500+ PHP versions simultaneously
<?php function sort_array_item_by_size($a, $b): int { static $sizes = [ "XXS" => 0, "XS" => 1, "S" => 2, "M" => 3, "L" => 4, "XL" => 5, "XXL" => 6, ]; // The next three lines really should include some error checking $size_a = explode("_", $a)[1]; $size_b = explode("_", $b)[1]; return $sizes[$size_a] <=> $sizes[$size_b]; } $your_array = ["GL001_XXL", "GL001_L", "GL001_XXS", "GL001_S"]; usort($your_array, "sort_array_item_by_size"); print_r($your_array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dqfi6
function name:  (null)
number of ops:  9
compiled vars:  !0 = $your_array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   ASSIGN                                                       !0, <array>
   24     1        INIT_FCALL                                                   'usort'
          2        SEND_REF                                                     !0
          3        SEND_VAL                                                     'sort_array_item_by_size'
          4        DO_ICALL                                                     
   26     5        INIT_FCALL                                                   'print_r'
          6        SEND_VAR                                                     !0
          7        DO_ICALL                                                     
          8      > RETURN                                                       1

Function sort_array_item_by_size:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Dqfi6
function name:  sort_array_item_by_size
number of ops:  22
compiled vars:  !0 = $a, !1 = $b, !2 = $sizes, !3 = $size_a, !4 = $size_b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        BIND_STATIC                                                  !2
   16     3        INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '_'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $5      
          7        FETCH_DIM_R                                          ~6      $5, 1
          8        ASSIGN                                                       !3, ~6
   17     9        INIT_FCALL                                                   'explode'
         10        SEND_VAL                                                     '_'
         11        SEND_VAR                                                     !1
         12        DO_ICALL                                             $8      
         13        FETCH_DIM_R                                          ~9      $8, 1
         14        ASSIGN                                                       !4, ~9
   19    15        FETCH_DIM_R                                          ~11     !2, !3
         16        FETCH_DIM_R                                          ~12     !2, !4
         17        SPACESHIP                                            ~13     ~11, ~12
         18        VERIFY_RETURN_TYPE                                           ~13
         19      > RETURN                                                       ~13
   20    20*       VERIFY_RETURN_TYPE                                           
         21*     > RETURN                                                       null

End of function sort_array_item_by_size

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.88 ms | 1784 KiB | 16 Q