3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'FILE-F01-E1-S01.pdf', 'FILE-F01-E1-S02.pdf', 'FILE-F01-E1-S03.pdf', 'FILE-F01-E1-S04.pdf', 'FILE-F01-E1-S05.pdf', 'FILE-F02-E1-S01.pdf', 'FILE-F02-E1-S02.pdf', 'FILE-F02-E1-S03.pdf', "TESTFILE-F01-E1-S03.pdf" ]; $parts = explode('-', $array[0]); array_pop($parts); $fileBeginning = implode('-', $parts); $secondArray = array_filter($array, function ($x) use ($fileBeginning) { return substr($x, 0, strlen($fileBeginning)) === $fileBeginning; }); print_r($secondArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6glNU
function name:  (null)
number of ops:  26
compiled vars:  !0 = $array, !1 = $parts, !2 = $fileBeginning, !3 = $secondArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   14     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '-'
          3        FETCH_DIM_R                                      ~5      !0, 0
          4        SEND_VAL                                                 ~5
          5        DO_ICALL                                         $6      
          6        ASSIGN                                                   !1, $6
   15     7        INIT_FCALL                                               'array_pop'
          8        SEND_REF                                                 !1
          9        DO_ICALL                                                 
   16    10        INIT_FCALL                                               'implode'
         11        SEND_VAL                                                 '-'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $9      
         14        ASSIGN                                                   !2, $9
   17    15        INIT_FCALL                                               'array_filter'
         16        SEND_VAR                                                 !0
         17        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2F6glNU%3A17%240'
         18        BIND_LEXICAL                                             ~11, !2
   19    19        SEND_VAL                                                 ~11
         20        DO_ICALL                                         $12     
   17    21        ASSIGN                                                   !3, $12
   20    22        INIT_FCALL                                               'print_r'
         23        SEND_VAR                                                 !3
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2F6glNU%3A17%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/6glNU
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $x, !1 = $fileBeginning
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   18     2        INIT_FCALL                                               'substr'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        STRLEN                                           ~2      !1
          6        SEND_VAL                                                 ~2
          7        DO_ICALL                                         $3      
          8        IS_IDENTICAL                                     ~4      !1, $3
          9      > RETURN                                                   ~4
   19    10*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F6glNU%3A17%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
184.02 ms | 1396 KiB | 25 Q