3v4l.org

run code in 300+ PHP versions simultaneously
<?php function glue($array, $allButLast = ', ', $last = ' and ') { if (empty($array)) { return ''; } $glued = implode($allButLast, $array); $pos = strrpos($glued, $allButLast); if ($pos !== false) { $glued = substr_replace($glued, $last, $pos, strlen($allButLast)); } return $glued; } $array = [ 'bar', 'food', 'foo, bar', ]; echo glue($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PScoI
function name:  (null)
number of ops:  6
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'glue'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function glue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/PScoI
function name:  glue
number of ops:  28
compiled vars:  !0 = $array, !1 = $allButLast, !2 = $last, !3 = $glued, !4 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '%2C+'
          2        RECV_INIT                                        !2      '+and+'
    5     3        ISSET_ISEMPTY_CV                                         !0
          4      > JMPZ                                                     ~5, ->6
    6     5    > > RETURN                                                   ''
    8     6    >   INIT_FCALL                                               'implode'
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !3, $6
    9    11        INIT_FCALL                                               'strrpos'
         12        SEND_VAR                                                 !3
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $8      
         15        ASSIGN                                                   !4, $8
   10    16        TYPE_CHECK                                  1018          !4
         17      > JMPZ                                                     ~10, ->26
   11    18    >   INIT_FCALL                                               'substr_replace'
         19        SEND_VAR                                                 !3
         20        SEND_VAR                                                 !2
         21        SEND_VAR                                                 !4
         22        STRLEN                                           ~11     !1
         23        SEND_VAL                                                 ~11
         24        DO_ICALL                                         $12     
         25        ASSIGN                                                   !3, $12
   14    26    > > RETURN                                                   !3
   15    27*     > RETURN                                                   null

End of function glue

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.45 ms | 1016 KiB | 17 Q