3v4l.org

run code in 300+ PHP versions simultaneously
<?php $postcodes = ['SO30 0NG', 'SO30 OTD', 'SO31 1TG', 'RG51 5HG', 'RG51 7GH']; $result= array(); Foreach ($postcodes as $postcode){ $short =Substr($postcode,0,4); If(!isset($result[$short])) $result[$short]=[]; $result[$short][]= $short; } Var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/YG08d
function name:  (null)
number of ops:  24
compiled vars:  !0 = $postcodes, !1 = $result, !2 = $postcode, !3 = $short
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    6     2      > FE_RESET_R                                       $6      !0, ->19
          3    > > FE_FETCH_R                                               $6, !2, ->19
    7     4    >   INIT_FCALL                                               'substr'
          5        SEND_VAR                                                 !2
          6        SEND_VAL                                                 0
          7        SEND_VAL                                                 4
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !3, $7
    8    10        ISSET_ISEMPTY_DIM_OBJ                         0  ~9      !1, !3
         11        BOOL_NOT                                         ~10     ~9
         12      > JMPZ                                                     ~10, ->15
         13    >   ASSIGN_DIM                                               !1, !3
         14        OP_DATA                                                  <array>
   10    15    >   FETCH_DIM_W                                      $12     !1, !3
         16        ASSIGN_DIM                                               $12
         17        OP_DATA                                                  !3
    6    18      > JMP                                                      ->3
         19    >   FE_FREE                                                  $6
   13    20        INIT_FCALL                                               'var_dump'
         21        SEND_VAR                                                 !1
         22        DO_ICALL                                                 
         23      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.32 ms | 1001 KiB | 15 Q