3v4l.org

run code in 300+ PHP versions simultaneously
<?php $postcodes = array( 'NE', 'NG', 'PE' ); function matches($needle, $postcodes) { foreach ($postcodes as $postcode) { if ($postcode === substr($needle, 0, strlen($postcode))) { return true; } } return false; } foreach (array('NE1', 'RG', 'PE') as $needle) { printf( "%s %s\n", $needle, matches($needle, $postcodes) ? 'matches' : 'does not match' ); } /* NE1 matches RG does not match PE matches */
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 17
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/oV3E4
function name:  (null)
number of ops:  19
compiled vars:  !0 = $postcodes, !1 = $needle
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   18     1      > FE_RESET_R                                       $3      <array>, ->17
          2    > > FE_FETCH_R                                               $3, !1, ->17
   19     3    >   INIT_FCALL                                               'printf'
   20     4        SEND_VAL                                                 '%25s+%25s%0A'
   21     5        SEND_VAR                                                 !1
   22     6        INIT_FCALL                                               'matches'
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !0
          9        DO_FCALL                                      0  $4      
         10      > JMPZ                                                     $4, ->13
         11    >   QM_ASSIGN                                        ~5      'matches'
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~5      'does+not+match'
         14    >   SEND_VAL                                                 ~5
         15        DO_ICALL                                                 
   18    16      > JMP                                                      ->2
         17    >   FE_FREE                                                  $3
   30    18      > RETURN                                                   1

Function matches:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 15
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/oV3E4
function name:  matches
number of ops:  18
compiled vars:  !0 = $needle, !1 = $postcodes, !2 = $postcode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    9     2      > FE_RESET_R                                       $3      !1, ->15
          3    > > FE_FETCH_R                                               $3, !2, ->15
   10     4    >   INIT_FCALL                                               'substr'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 0
          7        STRLEN                                           ~4      !2
          8        SEND_VAL                                                 ~4
          9        DO_ICALL                                         $5      
         10        IS_IDENTICAL                                             !2, $5
         11      > JMPZ                                                     ~6, ->14
   11    12    >   FE_FREE                                                  $3
         13      > RETURN                                                   <true>
    9    14    > > JMP                                                      ->3
         15    >   FE_FREE                                                  $3
   15    16      > RETURN                                                   <false>
   16    17*     > RETURN                                                   null

End of function matches

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.21 ms | 1402 KiB | 18 Q