3v4l.org

run code in 300+ PHP versions simultaneously
<?php print_r(createAddressLines('10 TOH GUAN ROAD, The Furniture Mall Bldg. The Furniture Mall Bldg. 06-01')); function createAddressLines($addressDetail) { $addressLines = [ 'addressLine1' => '', 'addressLine2' => '', 'addressLine3' => '' ]; if (35 >= strlen($addressDetail)) { $addressLines['addressLine1'] = $addressDetail; } else { $addressLineKeys = array_keys($addressLines); $lineIndex = 0; $addressWords = explode(' ', $addressDetail); foreach ($addressWords as $addressWord) { // Doesn't Fit in Current Line if (35 < strlen($addressLines[$addressLineKeys[$lineIndex]]) + 1 + strlen($addressWord)) { // Case where a Word Itself Exceed 35 Characters if (35 <= strlen($addressWord)) { if (2 > $lineIndex) { $leftSpace = 35 - strlen($addressLines[$addressLineKeys[$lineIndex]]); $addressLines[$addressLineKeys[$lineIndex]] .= ' ' . substr($addressWord, 0, $leftSpace); $lineIndex += 1; print_r('fdsa'.$lineIndex); $addressLines[$addressLineKeys[$lineIndex]] .= ' ' . substr($addressWord, $leftSpace, 35); continue; } } // Last Word on Line 3 if ($lineIndex == 2) { $addressLines[$addressLineKeys[$lineIndex]] .= ' ' . substr($addressWord, 0, 34 - strlen($addressLines[$addressLineKeys[$lineIndex]])); } // Go Next Line $lineIndex += 1; // Break if 3 Lines are Maxed if (3 <= $lineIndex) { break; } } $addressLines[$addressLineKeys[$lineIndex]] .= ' ' . $addressWord; } } return (object) $addressLines; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AIvCU
function name:  (null)
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL_BY_NAME                                       'createAddressLines'
          2        SEND_VAL_EX                                              '10+TOH+GUAN+ROAD%2C+The+Furniture+Mall+Bldg.+The+Furniture+Mall+Bldg.+06-01'
          3        DO_FCALL                                      0  $0      
          4        SEND_VAR                                                 $0
          5        DO_ICALL                                                 
   49     6      > RETURN                                                   1

Function createaddresslines:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 87
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 86
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 86
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 81
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 62
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 62
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 77
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 80, Position 2 = 81
Branch analysis from position: 80
1 jumps found. (Code = 42) Position 1 = 86
Branch analysis from position: 86
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 81
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 77
Branch analysis from position: 62
Branch analysis from position: 81
Branch analysis from position: 86
Branch analysis from position: 86
filename:       /in/AIvCU
function name:  createAddressLines
number of ops:  90
compiled vars:  !0 = $addressDetail, !1 = $addressLines, !2 = $addressLineKeys, !3 = $lineIndex, !4 = $addressWords, !5 = $addressWord, !6 = $leftSpace
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        ASSIGN                                                   !1, <array>
   13     2        STRLEN                                           ~8      !0
          3        IS_SMALLER_OR_EQUAL                                      ~8, 35
          4      > JMPZ                                                     ~9, ->8
   14     5    >   ASSIGN_DIM                                               !1, 'addressLine1'
          6        OP_DATA                                                  !0
          7      > JMP                                                      ->87
   16     8    >   INIT_FCALL                                               'array_keys'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $11     
         11        ASSIGN                                                   !2, $11
   17    12        ASSIGN                                                   !3, 0
   18    13        INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '+'
         15        SEND_VAR                                                 !0
         16        DO_ICALL                                         $14     
         17        ASSIGN                                                   !4, $14
   19    18      > FE_RESET_R                                       $16     !4, ->86
         19    > > FE_FETCH_R                                               $16, !5, ->86
   21    20    >   FETCH_DIM_R                                      ~17     !2, !3
         21        FETCH_DIM_R                                      ~18     !1, ~17
         22        STRLEN                                           ~19     ~18
         23        ADD                                              ~20     ~19, 1
         24        STRLEN                                           ~21     !5
         25        ADD                                              ~22     ~20, ~21
         26        IS_SMALLER                                               35, ~22
         27      > JMPZ                                                     ~23, ->81
   23    28    >   STRLEN                                           ~24     !5
         29        IS_SMALLER_OR_EQUAL                                      35, ~24
         30      > JMPZ                                                     ~25, ->62
   24    31    >   IS_SMALLER                                               !3, 2
         32      > JMPZ                                                     ~26, ->62
   25    33    >   FETCH_DIM_R                                      ~27     !2, !3
         34        FETCH_DIM_R                                      ~28     !1, ~27
         35        STRLEN                                           ~29     ~28
         36        SUB                                              ~30     35, ~29
         37        ASSIGN                                                   !6, ~30
   26    38        FETCH_DIM_R                                      ~32     !2, !3
         39        INIT_FCALL                                               'substr'
         40        SEND_VAR                                                 !5
         41        SEND_VAL                                                 0
         42        SEND_VAR                                                 !6
         43        DO_ICALL                                         $34     
         44        CONCAT                                           ~35     '+', $34
         45        ASSIGN_DIM_OP                .=               8          !1, ~32
         46        OP_DATA                                                  ~35
   27    47        ASSIGN_OP                                     1          !3, 1
   28    48        INIT_FCALL                                               'print_r'
         49        CONCAT                                           ~37     'fdsa', !3
         50        SEND_VAL                                                 ~37
         51        DO_ICALL                                                 
   29    52        FETCH_DIM_R                                      ~39     !2, !3
         53        INIT_FCALL                                               'substr'
         54        SEND_VAR                                                 !5
         55        SEND_VAR                                                 !6
         56        SEND_VAL                                                 35
         57        DO_ICALL                                         $41     
         58        CONCAT                                           ~42     '+', $41
         59        ASSIGN_DIM_OP                .=               8          !1, ~39
         60        OP_DATA                                                  ~42
   30    61      > JMP                                                      ->19
   34    62    >   IS_EQUAL                                                 !3, 2
         63      > JMPZ                                                     ~43, ->77
   35    64    >   FETCH_DIM_R                                      ~44     !2, !3
         65        INIT_FCALL                                               'substr'
         66        SEND_VAR                                                 !5
         67        SEND_VAL                                                 0
         68        FETCH_DIM_R                                      ~46     !2, !3
         69        FETCH_DIM_R                                      ~47     !1, ~46
         70        STRLEN                                           ~48     ~47
         71        SUB                                              ~49     34, ~48
         72        SEND_VAL                                                 ~49
         73        DO_ICALL                                         $50     
         74        CONCAT                                           ~51     '+', $50
         75        ASSIGN_DIM_OP                .=               8          !1, ~44
         76        OP_DATA                                                  ~51
   38    77    >   ASSIGN_OP                                     1          !3, 1
   40    78        IS_SMALLER_OR_EQUAL                                      3, !3
         79      > JMPZ                                                     ~53, ->81
   41    80    > > JMP                                                      ->86
   44    81    >   FETCH_DIM_R                                      ~54     !2, !3
         82        CONCAT                                           ~56     '+', !5
         83        ASSIGN_DIM_OP                .=               8          !1, ~54
         84        OP_DATA                                                  ~56
   19    85      > JMP                                                      ->19
         86    >   FE_FREE                                                  $16
   48    87    >   CAST                                          8  ~57     !1
         88      > RETURN                                                   ~57
   49    89*     > RETURN                                                   null

End of function createaddresslines

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.96 ms | 1404 KiB | 21 Q