3v4l.org

run code in 300+ PHP versions simultaneously
<?php $before = [ ['type' => 'foo'], ['type' => 'only-first-of-this'], ['type' => 'bar'], ['type' => 'only-first-of-this'], ['type' => 'baz'], ]; $found = 0; $after = array_filter( $before, static fn ($item) => $item['type'] !== 'only-first-of-this' || $found++ === 0, ); var_dump($before, $after); $found = 0; $after2 = array_filter( $before, static function ($item) use (&$found) { return $item['type'] !== 'only-first-of-this' || $found++ === 0; }, ); var_dump($after2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8Z98j
function name:  (null)
number of ops:  25
compiled vars:  !0 = $before, !1 = $found, !2 = $after, !3 = $after2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, 0
   12     2        INIT_FCALL                                               'array_filter'
   13     3        SEND_VAR                                                 !0
   14     4        DECLARE_LAMBDA_FUNCTION                          ~6      [0]
          5        BIND_LEXICAL                                             ~6, !1
          6        SEND_VAL                                                 ~6
   12     7        DO_ICALL                                         $7      
          8        ASSIGN                                                   !2, $7
   17     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !2
         12        DO_ICALL                                                 
   19    13        ASSIGN                                                   !1, 0
   20    14        INIT_FCALL                                               'array_filter'
   21    15        SEND_VAR                                                 !0
   22    16        DECLARE_LAMBDA_FUNCTION                          ~11     [1]
         17        BIND_LEXICAL                                             ~11, !1
         18        SEND_VAL                                                 ~11
   20    19        DO_ICALL                                         $12     
         20        ASSIGN                                                   !3, $12
   25    21        INIT_FCALL                                               'var_dump'
         22        SEND_VAR                                                 !3
         23        DO_ICALL                                                 
         24      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/8Z98j
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $item, !1 = $found
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_DIM_R                                      ~2      !0, 'type'
          3        IS_NOT_IDENTICAL                                 ~3      ~2, 'only-first-of-this'
          4      > JMPNZ_EX                                         ~3      ~3, ->8
          5    >   POST_INC                                         ~4      !1
          6        IS_IDENTICAL                                     ~5      ~4, 0
          7        BOOL                                             ~3      ~5
          8    > > RETURN                                                   ~3
          9*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/8Z98j
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $item, !1 = $found
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_DIM_R                                      ~2      !0, 'type'
          3        IS_NOT_IDENTICAL                                 ~3      ~2, 'only-first-of-this'
          4      > JMPNZ_EX                                         ~3      ~3, ->8
          5    >   POST_INC                                         ~4      !1
          6        IS_IDENTICAL                                     ~5      ~4, 0
          7        BOOL                                             ~3      ~5
          8    > > RETURN                                                   ~3
          9*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.14 ms | 960 KiB | 15 Q