3v4l.org

run code in 300+ PHP versions simultaneously
<?php function change_top_items($array, $top_x) { uasort($array, function($a, $b) { if ($a == $b) return 0; return ($a < $b) ? -1 : 1; }); $compare = array_slice($array, -$top_x); $modified = array_map(function($value) use ($compare) { return in_array($value, $compare) ? 1 : 0; }, $array); ksort($modified); return $modified; } $a = [5, 8, 2, 0, 1, 9, 1, 0, 5, 4]; print_r(change_top_items($a, 5));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A1A7R
function name:  (null)
number of ops:  9
compiled vars:  !0 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, <array>
   29     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'change_top_items'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 5
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function change_top_items:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A1A7R
function name:  change_top_items
number of ops:  25
compiled vars:  !0 = $array, !1 = $top_x, !2 = $compare, !3 = $modified
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        INIT_FCALL                                               'uasort'
          3        SEND_REF                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
   11     5        SEND_VAL                                                 ~4
    5     6        DO_ICALL                                                 
   13     7        INIT_FCALL                                               'array_slice'
          8        SEND_VAR                                                 !0
          9        MUL                                              ~6      !1, -1
         10        SEND_VAL                                                 ~6
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   15    13        INIT_FCALL                                               'array_map'
         14        DECLARE_LAMBDA_FUNCTION                          ~9      [1]
         15        BIND_LEXICAL                                             ~9, !2
   19    16        SEND_VAL                                                 ~9
         17        SEND_VAR                                                 !0
   15    18        DO_ICALL                                         $10     
         19        ASSIGN                                                   !3, $10
   21    20        INIT_FCALL                                               'ksort'
         21        SEND_REF                                                 !3
         22        DO_ICALL                                                 
   23    23      > RETURN                                                   !3
   25    24*     > RETURN                                                   null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A1A7R
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        IS_EQUAL                                                 !0, !1
          3      > JMPZ                                                     ~2, ->5
          4    > > RETURN                                                   0
    9     5    >   IS_SMALLER                                               !0, !1
          6      > JMPZ                                                     ~3, ->9
          7    >   QM_ASSIGN                                        ~4      -1
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~4      1
         10    > > RETURN                                                   ~4
   11    11*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 9
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A1A7R
function name:  {closure}
number of ops:  12
compiled vars:  !0 = $value, !1 = $compare
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   17     2        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6      > JMPZ                                                     $2, ->9
          7    >   QM_ASSIGN                                        ~3      1
          8      > JMP                                                      ->10
          9    >   QM_ASSIGN                                        ~3      0
         10    > > RETURN                                                   ~3
   19    11*     > RETURN                                                   null

End of Dynamic Function 1

End of function change_top_items

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.04 ms | 1011 KiB | 20 Q