3v4l.org

run code in 300+ PHP versions simultaneously
<?php $allowed_ext = array ( 'bmp', 'jpg', 'jpeg', 'gif', 'pdf' ); $arr = array( 1 => 'file-to-path/thumbs/allowedfile.pdf', 2 => 'file-to-path/thumbs/notallowedfile.psd', 3 => 'file-to-path/project/test/notallowedfile.txt' ); $errors = []; foreach ($arr as $key => $value) { if (!in_array(pathinfo($value, PATHINFO_EXTENSION), $allowed_ext)) { $errors[] = basename($value).' is not allowed.'; unset($arr[$key]); } } print_r($errors); print_r($arr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 23
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 23
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/oSOJT
function name:  (null)
number of ops:  32
compiled vars:  !0 = $allowed_ext, !1 = $arr, !2 = $errors, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   16     2        ASSIGN                                                   !2, <array>
   18     3      > FE_RESET_R                                       $8      !1, ->24
          4    > > FE_FETCH_R                                       ~9      $8, !3, ->24
          5    >   ASSIGN                                                   !4, ~9
   19     6        INIT_FCALL                                               'in_array'
          7        INIT_FCALL                                               'pathinfo'
          8        SEND_VAR                                                 !3
          9        SEND_VAL                                                 4
         10        DO_ICALL                                         $11     
         11        SEND_VAR                                                 $11
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $12     
         14        BOOL_NOT                                         ~13     $12
         15      > JMPZ                                                     ~13, ->23
   20    16    >   INIT_FCALL                                               'basename'
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $15     
         19        CONCAT                                           ~16     $15, '+is+not+allowed.'
         20        ASSIGN_DIM                                               !2
         21        OP_DATA                                                  ~16
   21    22        UNSET_DIM                                                !1, !4
   18    23    > > JMP                                                      ->4
         24    >   FE_FREE                                                  $8
   25    25        INIT_FCALL                                               'print_r'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                                 
   27    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !1
         30        DO_ICALL                                                 
   29    31      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
269.61 ms | 1014 KiB | 17 Q