3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('MY_ORDER', [0 => 2, 1 => 3, 2 => 0, 8 => 1]); $array = [2, 2, 2, 1, 1, 0, 0, 8]; usort($array, function ($a, $b) { static $cache; return ($cache[$a] ??= keyfn($a)) <=> ($cache[$b] ??= keyfn($b)); }); var_export($array); function keyfn($v) { echo "called for $v\n"; return MY_ORDER[$v]; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/olhnd
function name:  (null)
number of ops:  14
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'MY_ORDER'
          2        SEND_VAL                                                 <array>
          3        DO_ICALL                                                 
    5     4        ASSIGN                                                   !0, <array>
    6     5        INIT_FCALL                                               'usort'
          6        SEND_REF                                                 !0
          7        DECLARE_LAMBDA_FUNCTION                          ~3      [0]
    9     8        SEND_VAL                                                 ~3
    6     9        DO_ICALL                                                 
   10    10        INIT_FCALL                                               'var_export'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                                 
   15    13      > 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/olhnd
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $a, !1 = $b, !2 = $cache
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        BIND_STATIC                                              !2
    8     3        FETCH_DIM_IS                                     ~3      !2, !0
          4        COALESCE                                         ~4      ~3
          5        INIT_FCALL_BY_NAME                                       'keyfn'
          6        SEND_VAR_EX                                              !0
          7        DO_FCALL                                      0  $5      
          8        ASSIGN_DIM                                       ~6      !2, !0
          9        OP_DATA                                                  $5
         10        QM_ASSIGN                                        ~4      ~6
         11        FETCH_DIM_IS                                     ~7      !2, !1
         12        COALESCE                                         ~8      ~7
         13        INIT_FCALL_BY_NAME                                       'keyfn'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0  $9      
         16        ASSIGN_DIM                                       ~10     !2, !1
         17        OP_DATA                                                  $9
         18        QM_ASSIGN                                        ~8      ~10
         19        SPACESHIP                                        ~11     ~4, ~8
         20      > RETURN                                                   ~11
    9    21*     > RETURN                                                   null

End of Dynamic Function 0

Function keyfn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/olhnd
function name:  keyfn
number of ops:  9
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ROPE_INIT                                     3  ~2      'called+for+'
          2        ROPE_ADD                                      1  ~2      ~2, !0
          3        ROPE_END                                      2  ~1      ~2, '%0A'
          4        ECHO                                                     ~1
   14     5        FETCH_CONSTANT                                   ~4      'MY_ORDER'
          6        FETCH_DIM_R                                      ~5      ~4, !0
          7      > RETURN                                                   ~5
   15     8*     > RETURN                                                   null

End of function keyfn

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.13 ms | 1017 KiB | 16 Q