3v4l.org

run code in 500+ PHP versions simultaneously
<?php $my_array_to_sort= [ "data"=> [ 0=>["name"=>"orange", "id"=>23423], 1=>["name"=>"green", "id"=>34343], 2=>["name"=>"red", "id"=>65566], ] ]; $priority = [ "red"=>1, "orange"=>2, "green"=>3, ]; usort($my_array_to_sort['data'], function ($a, $b) use ($priority) { return $priority[$a['name']] - $priority[$b['name']]; }); print_r($my_array_to_sort); usort($my_array_to_sort['data'], function ($a, $b) use ($priority) { return $priority[$b['name']] - $priority[$a['name']]; }); print_r($my_array_to_sort);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kF34H
function name:  (null)
number of ops:  23
compiled vars:  !0 = $my_array_to_sort, !1 = $priority
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   14     1        ASSIGN                                                       !1, <array>
   20     2        INIT_FCALL                                                   'usort'
          3        FETCH_DIM_W                                          $4      !0, 'data'
          4        SEND_REF                                                     $4
          5        DECLARE_LAMBDA_FUNCTION                              ~5      [0]
          6        BIND_LEXICAL                                                 ~5, !1
   22     7        SEND_VAL                                                     ~5
   20     8        DO_ICALL                                                     
   24     9        INIT_FCALL                                                   'print_r'
         10        SEND_VAR                                                     !0
         11        DO_ICALL                                                     
   26    12        INIT_FCALL                                                   'usort'
         13        FETCH_DIM_W                                          $8      !0, 'data'
         14        SEND_REF                                                     $8
         15        DECLARE_LAMBDA_FUNCTION                              ~9      [1]
         16        BIND_LEXICAL                                                 ~9, !1
   28    17        SEND_VAL                                                     ~9
   26    18        DO_ICALL                                                     
   30    19        INIT_FCALL                                                   'print_r'
         20        SEND_VAR                                                     !0
         21        DO_ICALL                                                     
         22      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kF34H
function name:  {closure:/in/kF34H:20}
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $priority
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   21     3        FETCH_DIM_R                                          ~3      !0, 'name'
          4        FETCH_DIM_R                                          ~4      !2, ~3
          5        FETCH_DIM_R                                          ~5      !1, 'name'
          6        FETCH_DIM_R                                          ~6      !2, ~5
          7        SUB                                                  ~7      ~4, ~6
          8      > RETURN                                                       ~7
   22     9*     > RETURN                                                       null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/kF34H
function name:  {closure:/in/kF34H:26}
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $priority
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
   27     3        FETCH_DIM_R                                          ~3      !1, 'name'
          4        FETCH_DIM_R                                          ~4      !2, ~3
          5        FETCH_DIM_R                                          ~5      !0, 'name'
          6        FETCH_DIM_R                                          ~6      !2, ~5
          7        SUB                                                  ~7      ~4, ~6
          8      > RETURN                                                       ~7
   28     9*     > RETURN                                                       null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
175.16 ms | 2331 KiB | 15 Q