3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ 'Wellington New Zealand', 'Florida United States of America', 'Quebec Canada', 'Something Country XYZ (formally ABC)', ]; $countries = [ 'United States of America', 'Canada', 'New Zealand', 'Country XYZ (formally ABC)', ]; $branches = array_map(fn($country) => preg_quote($country, '/'), $countries); $result = []; foreach ($data as $string) { $result[] = preg_split('/ (?=(?:' . implode('|', $branches) . ')$)/', $string, 2); } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/7pjIL
function name:  (null)
number of ops:  27
compiled vars:  !0 = $data, !1 = $countries, !2 = $branches, !3 = $result, !4 = $string
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   10     1        ASSIGN                                                       !1, <array>
   17     2        INIT_FCALL                                                   'array_map'
          3        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
          4        SEND_VAL                                                     ~7
          5        SEND_VAR                                                     !1
          6        DO_ICALL                                             $8      
          7        ASSIGN                                                       !2, $8
   19     8        ASSIGN                                                       !3, <array>
   20     9      > FE_RESET_R                                           $11     !0, ->22
         10    > > FE_FETCH_R                                                   $11, !4, ->22
   21    11    >   INIT_FCALL                                                   'preg_split'
         12        FRAMELESS_ICALL_2                implode             ~13     '%7C', !2
         13        CONCAT                                               ~14     '%2F+%28%3F%3D%28%3F%3A', ~13
         14        CONCAT                                               ~15     ~14, '%29%24%29%2F'
         15        SEND_VAL                                                     ~15
         16        SEND_VAR                                                     !4
         17        SEND_VAL                                                     2
         18        DO_ICALL                                             $16     
         19        ASSIGN_DIM                                                   !3
         20        OP_DATA                                                      $16
   20    21      > JMP                                                          ->10
         22    >   FE_FREE                                                      $11
   23    23        INIT_FCALL                                                   'var_export'
         24        SEND_VAR                                                     !3
         25        DO_ICALL                                                     
         26      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7pjIL
function name:  {closure:/in/7pjIL:17}
number of ops:  7
compiled vars:  !0 = $country
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
          1        INIT_FCALL                                                   'preg_quote'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     '%2F'
          4        DO_ICALL                                             $1      
          5      > RETURN                                                       $1
          6*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
164.3 ms | 1946 KiB | 17 Q