3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [2,2,2,1,1,0,0,8]; $values_cache = []; usort($array, function ($a, $b) use (&$values_cache) { $key_a = isset($values_cache[$a]) ? $values_cache[$a] : ($values_cache[$a] = keyfn($a)); $key_b = isset($values_cache[$b]) ? $values_cache[$b] : ($values_cache[$b] = keyfn($b)); return $key_a <=> $key_b; }); echo '<pre>', print_r($array), '</pre>'; // TODO function keyfn($v) { echo 'call a keyfn' . PHP_EOL; return 2 * $v; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W1N7Y
function name:  (null)
number of ops:  15
compiled vars:  !0 = $array, !1 = $values_cache
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'usort'
          3        SEND_REF                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FW1N7Y%3A5%240'
          5        BIND_LEXICAL                                             ~4, !1
    9     6        SEND_VAL                                                 ~4
          7        DO_ICALL                                                 
   10     8        ECHO                                                     '%3Cpre%3E'
          9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $6      
         12        ECHO                                                     $6
         13        ECHO                                                     '%3C%2Fpre%3E'
   15    14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FW1N7Y%3A5%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
Branch analysis from position: 20
filename:       /in/W1N7Y
function name:  {closure}
number of ops:  30
compiled vars:  !0 = $a, !1 = $b, !2 = $values_cache, !3 = $key_a, !4 = $key_b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
    6     3        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !0
          4      > JMPZ                                                     ~5, ->8
          5    >   FETCH_DIM_R                                      ~6      !2, !0
          6        QM_ASSIGN                                        ~7      ~6
          7      > JMP                                                      ->14
          8    >   INIT_FCALL_BY_NAME                                       'keyfn'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $9      
         11        ASSIGN_DIM                                       ~8      !2, !0
         12        OP_DATA                                                  $9
         13        QM_ASSIGN                                        ~7      ~8
         14    >   ASSIGN                                                   !3, ~7
    7    15        ISSET_ISEMPTY_DIM_OBJ                         0          !2, !1
         16      > JMPZ                                                     ~11, ->20
         17    >   FETCH_DIM_R                                      ~12     !2, !1
         18        QM_ASSIGN                                        ~13     ~12
         19      > JMP                                                      ->26
         20    >   INIT_FCALL_BY_NAME                                       'keyfn'
         21        SEND_VAR_EX                                              !1
         22        DO_FCALL                                      0  $15     
         23        ASSIGN_DIM                                       ~14     !2, !1
         24        OP_DATA                                                  $15
         25        QM_ASSIGN                                        ~13     ~14
         26    >   ASSIGN                                                   !4, ~13
    8    27        SPACESHIP                                        ~17     !3, !4
         28      > RETURN                                                   ~17
    9    29*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FW1N7Y%3A5%240

Function keyfn:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/W1N7Y
function name:  keyfn
number of ops:  5
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1        ECHO                                                     'call+a+keyfn%0A'
   14     2        MUL                                              ~1      !0, 2
          3      > RETURN                                                   ~1
   15     4*     > RETURN                                                   null

End of function keyfn

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.91 ms | 1400 KiB | 17 Q