3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('MY_ORDER', [0 => 2, 1 => 3, 2 => 0, 8 => 1]); function keyfn($v) { echo "called for $v\n"; return MY_ORDER[$v]; } $array = [2, 2, 2, 1, 1, 0, 0, 8]; $new = []; foreach ($array as $v) { $new[] = $cache[$v] ??= keyfn($v); } array_multisort($new, $array); var_export($array);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 19
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/WSHNl
function name:  (null)
number of ops:  28
compiled vars:  !0 = $array, !1 = $new, !2 = $v, !3 = $cache
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                                                 
    9     4        ASSIGN                                                   !0, <array>
   11     5        ASSIGN                                                   !1, <array>
   12     6      > FE_RESET_R                                       $7      !0, ->19
          7    > > FE_FETCH_R                                               $7, !2, ->19
   13     8    >   FETCH_DIM_IS                                     ~9      !3, !2
          9        COALESCE                                         ~10     ~9
         10        INIT_FCALL                                               'keyfn'
         11        SEND_VAR                                                 !2
         12        DO_FCALL                                      0  $11     
         13        ASSIGN_DIM                                       ~12     !3, !2
         14        OP_DATA                                                  $11
         15        QM_ASSIGN                                        ~10     ~12
         16        ASSIGN_DIM                                               !1
         17        OP_DATA                                                  ~10
   12    18      > JMP                                                      ->7
         19    >   FE_FREE                                                  $7
   15    20        INIT_FCALL                                               'array_multisort'
         21        SEND_REF                                                 !1
         22        SEND_REF                                                 !0
         23        DO_ICALL                                                 
   16    24        INIT_FCALL                                               'var_export'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                                 
         27      > RETURN                                                   1

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

End of function keyfn

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.53 ms | 1403 KiB | 20 Q