3v4l.org

run code in 300+ PHP versions simultaneously
<?php function startsWith($haystack, $needle) { // search backwards starting from haystack length characters from the end return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false; } $mustcontain = 'url/sub/dir/'; $links = array ( 0 => 'url/sub/dir/1234', 1 => 'url/sub/dir/', 2 => 'url/13214124', 3 => 'url/sub/123123123123', ); $finalArr = array(); foreach($links as $v){ if(startsWith($v, $mustcontain)){ $finalArr[] = $v; } } print_r($finalArr);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/5gtqe
function name:  (null)
number of ops:  18
compiled vars:  !0 = $mustcontain, !1 = $links, !2 = $finalArr, !3 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, 'url%2Fsub%2Fdir%2F'
    9     1        ASSIGN                                                   !1, <array>
   16     2        ASSIGN                                                   !2, <array>
   18     3      > FE_RESET_R                                       $7      !1, ->13
          4    > > FE_FETCH_R                                               $7, !3, ->13
   19     5    >   INIT_FCALL                                               'startswith'
          6        SEND_VAR                                                 !3
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0  $8      
          9      > JMPZ                                                     $8, ->12
   20    10    >   ASSIGN_DIM                                               !2
         11        OP_DATA                                                  !3
   18    12    > > JMP                                                      ->4
         13    >   FE_FREE                                                  $7
   24    14        INIT_FCALL                                               'print_r'
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function startswith:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/5gtqe
function name:  startsWith
number of ops:  15
compiled vars:  !0 = $haystack, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        IS_IDENTICAL                                     ~2      !1, ''
          3      > JMPNZ_EX                                         ~2      ~2, ->13
          4    >   INIT_FCALL                                               'strrpos'
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !1
          7        STRLEN                                           ~3      !0
          8        MUL                                              ~4      ~3, -1
          9        SEND_VAL                                                 ~4
         10        DO_ICALL                                         $5      
         11        TYPE_CHECK                                  1018  ~6      $5
         12        BOOL                                             ~2      ~6
         13    > > RETURN                                                   ~2
    6    14*     > RETURN                                                   null

End of function startswith

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.2 ms | 1403 KiB | 18 Q